// ROOT : DRAGON3012009 : WA in Real Life
#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
#define FORD(i,r,l) for(int i = r ; i >= l ; i --)
#define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
#define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end());
#define ll int
#define el "\n"
#define fi first
#define se second
#define _ROOT_ int main()
#define M 1000000007
#define MAXN 1000001
#define INF (1ll<<30)
#define NAME "file"
#define debug(a) cout << #a << " = " << a << endl;
using namespace std;

ll n, m, q ;
ll a[MAXN] ;
ll lab[MAXN ] ;
vector<ll> adj[MAXN ] ;
vector<pair<ll,ll>> history ;

ll find_set(ll a ) {
    return lab[a] < 0 ? a : find_set(lab[a]) ;
}

bool union_set(ll a, ll b ) {
    a = find_set(a) ;
    b = find_set(b) ;
    if(a == b ) return false ;
    if(lab[a] > lab[b] ) swap(a, b ) ;
    history.push_back({a, lab[a] }) ;
    history.push_back({b, lab[b] }) ;
    lab[a] += lab[b] ;
    lab[b] = a ;
    return true ;
}

void rollBack(ll te ) {
    while(history.size() > te ) {
        lab[history.back().fi ] = history.back().se ;
        history.pop_back() ;
    }
}

bool cmp(ll x, ll y ) {
    return a[x] < a[y] ;
}

void init() {
    history.clear() ;
    cin >> n  >> m ;
    FOR(i, 1, n ) {
        cin >> a[i] ;
        lab[i] = - 1 ;
    }
    FOR(i, 1, m ) {
        ll x, y ;
        cin >> x >> y ;
        adj[x].push_back(y) ;
        adj[y].push_back(x) ;
        if(a[x] == a[y]) union_set(x, y ) ;
    }
}

void solve() {
    ll ans = 0 ;

    FOR(u, 1, n ) ans = max(ans, -lab[u]) ;

//    FOR(i , 1 , n ) debug(lab[i]) ;

    FOR(u, 1, n ) {
    sort(adj[u].begin(), adj[u].end(), cmp ) ;
//    cout << u << " u : "  ;
//    for(ll v : adj[u]) cout << v << " " ; cout << el ;
    }


    FOR(u, 1, n ) {
        ll last = -1 ;
        ll snap = history.size() ;
        ll cur_color = - 1 ;
        for(ll v : adj[u] ) {
            if(last != a[v] ) {
                rollBack(snap ) ;
                last = a[v] ;
                cur_color = v ;
            }
            last = a[v] ;
            union_set(v, cur_color ) ;
            if(a[u] == a[v ]) ans = max(ans, -lab[find_set(cur_color)]  ) ;
            else ans = max(ans, -lab[find_set(cur_color)] + 1 ) ;
        }
        rollBack(snap ) ;
    }
    FOR(i , 1 , n ) adj[i].clear() ;
    cout << ans << el ;
}

_ROOT_ {
    // freopen(NAME".inp" , "r" , stdin);
    // freopen(NAME".out" , "w", stdout) ;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t ;
    while(t--) {
        init();
        solve();
    }
    return (0&0);
}
