# WA in SORTVS

I am getting WA for this

import java.io.;
import java.math.
;
import java.security.;
import java.text.
;
import java.util.;
import java.util.concurrent.
;
import java.util.regex.*;

class Solution {

public static void main(String[] args)
{int i,t,j,b,w,n,t1,m,t2;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
try{
while(t>0){ n=sc.nextInt();
int r=1;
m=sc.nextInt();
int a[]=new int[n];
int k[][]=new int[m][2];
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();

``````     }
for(i=0;i<m;i++)
{
for(j=0;j<2;j++)
{ k[i][j]=sc.nextInt();
}
}
for(i=0;i<m;i++)
{if(k[i][0]!=r&&k[i][1]!=r)
{
r++;
}
t2=k[i][0]-1;
t1=k[i][1]-1;
b=a[t2];
if(a[r-1]!=r)
{
a[t2]=a[t1];
a[t1]=b;
}
}
if((csort(a))==0)
{
System.out.println("0");
}
else
{
w=sort(a);
System.out.println(w);
}t--;
}
}catch(Exception e){
``````

return;
}
}
static int csort(int a[])
{
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return -1;
}
}
return 0;
}
static int sort(int arr[])
{int temp,k=0;
for (int i = 0; i < arr.length; i++) {
for (int j = i+1; j < arr.length; j++) {
if(arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
k++;
}
}
}
return k;
}
}