#include<iostream>
using namespace std;
#include<cstring>
int N[200][2];
int T[200][2];
bool vis[200];
int main(){
	int n,m;
	cin>>n>>m;
	int tot=0;
	for(int i=1;i<=m;i++){
		tot++;
		cin>>N[tot][0]>>N[tot][1];
	}
	int k;cin>>k;tot=0;
	for(int i=1;i<=k;i++){
		tot++;
		cin>>T[tot][0]>>T[tot][1]; 
	}
	int ans=0;
	for(int i=0;i<(1<<16);i++){
		int tmp=i;
		int cnt=0;
		memset(vis,0,sizeof(vis));
		for(int v=1;v<=k;v++){
			vis[T[v][tmp&1]]=1;
			tmp>>=1;
		}
		for(int j=1;j<=m;j++){
			if(vis[N[j][0]]&&vis[N[j][1]])cnt++;
		}
		ans=max(ans,cnt);
	}
	cout<<ans;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cassert>
#include <set>
using namespace std;

const long long MOD = 1e9 + 7;
vector<long long> fact, fact_inv, inv;

void init_nCk(long long SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}

long long nCk(long long n, long long k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

int main()
{
    long long n;
    scanf("%lld", &n);
    string s;
    cin >> s;
    long long q;
    cin >> q;
    long long t, a, b;
    char c;
    string temp1, temp2;
    bool flag = false;
    for (long long i = 0; i < q; i++) {
        cin >> t >> a >> b;
        a--;
        b--;
        if (t == 1) {
            if (!flag) {
                c = s[a];
                s[a] = s[b];
                s[b] = c;
            } else {
                a = a >= n ? a - n: a + n ;
                b = b >= n ? b - n: b + n;
                c = s[a];
                s[a] = s[b];
                s[b] = c;
            }
        } else {
            flag = !flag;
        }
    }
    if (flag) {
        s = s.substr(n, 2 * n) + s.substr(0, n);
    }
    cout << s << endl;

    return 0;
}
