#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    ll n,m,k,ans=0;
    cin>>n>>m;
    vector<vector<ll>> a(m,vector<ll>(2));
    vector<ll> c(n+1,0);
    for(ll i=0;i<m;i++) cin>>a[i][0]>>a[i][1];
    cin>>k;
    vector<vector<ll>> b(k,vector<ll>(2));
    for(ll i=0;i<k;i++) cin>>b[i][0]>>b[i][1];
    for(ll i=0;i<(1LL<<k);i++)
    {
        ll x=0;
        for(ll j=0;j<k;j++) 
        {
            if((1LL<<j)&i) c[b[j][1]]=1;
            else c[b[j][0]]=1;
        }
        for(ll j=0;j<m;j++)
        {
            if(c[a[j][0]]&&c[a[j][1]]) x++;
        }
        for(ll j=0;j<=n;j++) c[j]=0;
        ans=max(ans,x);
    }
    cout<<ans;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}
struct UnionFind {
    vector<int> data;
    vector<map<int, int>> mp;
    UnionFind(int size, vector<map<int, int>> _mp) : data(size, -1), mp(_mp) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            for (auto [key, num] : mp[y]) {
                mp[x][key] += num;
            }
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, q;
    cin >> n >> q;
    vector<map<int, int>> mp(n);
    rep(i, n) {
        int c;
        cin >> c;
        mp[i][c] = 1;
    }
    UnionFind uf(n, mp);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            uf.unite(a, b);
        }
        if (t == 2) {
            int x, y;
            cin >> x >> y;
            x--;
            cout << uf.mp[uf.root(x)][y] << '\n';
        }
    }
}