#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
struct DSU {
vector<int> par, rank, sz;
int c;
DSU(int n) : par(n + 1), rank(n + 1, 0), sz(n + 1, 1), c(n) {
for (int i = 1; i <= n; i++) par[i] = i;
}
int find(int v) {
if (par[v] == v) return v;
else return par[v] = find(par[v]);
}
bool same(int a, int b) {
return find(a) == find(b);
}
int get_size(int v) {
return sz[find(v)];
}
int count() {
return c;
}
void merge(int a, int b) {
a = find(a), b = find(b);
if (a == b) return;
c--;
if (rank[a] > rank[b]) swap(a, b);
par[a] = b;
sz[b] += sz[a];
if (rank[a] == rank[b]) rank[b]++;
}
};
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--){
int n, q;
cin >> n >> q;
vector<int> a(n+1);
for (int i = 0; i < n; i++){
cin >> a[i];
}
DSU dsu(n + 1);
while (q--){
int x, y;
cin >> x >> y;
dsu.merge(a[x - 1], a[y - 1]);
}
int mx = 0;
for (int i = 1; i <= n; i++){
mx = max(mx, dsu.get_size(i));
}
cout << mx << endl;
}
}