#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int j,n,q,i,c[100],u[100],v[100],m[100],br=0,x[100],r[100],l[100],a[100],b[100],y,z,pom,max;
	printf("unesi broj naselja\n");
	scanf("%d",&n);
	printf("unesi reedosled naselja\n");
	for(i=0;i<n;i++)
		{
			scanf("%d",a[i]);
		}
	for(i=0;i<n-1;i++)
		{
			printf("unesi broj put izmedju naselja\n");
			scanf("%d%d",&u[i],v[i]);
		}
	printf("koliko dogadjaja se desilo\n");
	scanf("%d",&q);
	for(i=0;i<q;i++)
		{
			printf("unesi dogadjaj\n");
			scanf("%d",&m[i]);
		}
	for(i=0;i<q;i++)
		{
			y=m[i];
			while(y>0)
				{
					y=y/10;
					br++;	
				}
			z=m[i];
			if(br==4)
				{
					x[i]=m[i]%10;
					m[i]=m[i]/10;
					r[i]=m[i]%10;
					m[i]=m[i]/10;
					l[i]=m[i]%10;
					m[i]=m[i]/10;
				}
			br=0;
			if(br==3)
				{
					c[i]=z%10;
					z=z/10;
					c[i]=z%10;
					z=z%10;
				}
			else
				printf("gresa pri unosu\n");
		}	
	for(i=0;i<q;i++);
		y=m[i];
		while(y>0)
				{
					y=y/10;
					br++;	
				}
		if(br==3)
			{
				a[c[i]]=pom;
				pom=a[b[i]];
				a[b[i]]=a[c[i]];
			}
		if(br==4)
			{
				for(i=0;i<n;i++)
					for(j=i+1;j<n;j++)
					{
						if(u(i)==v(j))
							if(v(j)==max)
								printf("%d",j-i);
					}
			}
	return 0;
}