
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define bitcount(x) (int)__builtin_popcount(x) 

int n, m, dp[19][1<<19] ; 

vector <pair<int, int>> g[20] ; 

int fun(int idx, int mask) {
    int &ans = dp[idx][mask] ; 
    if (ans != -1) return ans ; 
    ans = 0 ; 
    bool ok = true ; 
    for (auto &it: g[idx]) {
        int c = bitcount(((1<<it.first)-1) & mask) ; 
        if (c > it.second) {
            ok = 0 ; 
            break ; 
        }
    }
    if (!ok) {
        ans = 0 ; 
        return 0 ; 
    }
    if (idx == n) {
        ans = 1 ; 
        return ans ; 
    }
    for (int i=0;i<n;++i) {
        if (!(mask&(1<<i))) {
            ans += fun(idx+1, mask|(1<<i)) ; 
        }
    }
    ans = max(ans, 0LL) ; 
    return ans ; 
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); 

    cin >> n >> m ; 
    for (int i=1;i<=m;++i) {
        int a, b, c ; 
        cin >> a >> b >> c ; 
        g[a].push_back({b, c}) ; 
    }
    memset(dp, -1, sizeof(dp)) ; 
    int ans = 0;
    for (int i=0;i<n;++i) {
        ans += fun(1, 1<<i) ; 
    }
    cout << ans << endl ; 
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

void f(string &X, string &Y, int t, int a, int b, int N) {
    if (t == 2) {
        swap(X, Y);
        return;
    }
    
    if (a < N && b < N) {
        swap(X.at(a), X.at(b));
    } else if (a < N && b >= N) {
        swap(X.at(a), Y.at(b-N));
    } else if (a >= N && b < N) {
        swap(Y.at(a-N), X.at(b));
    } else if (a >= N && b >= N) {
        swap(Y.at(a-N), Y.at(b-N));
    }
    return;
}

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<int> T(Q), A(Q), B(Q);
    for (int i = 0; i < Q; i++) {
        cin >> T.at(i) >> A.at(i) >> B.at(i);
    }

    string X(N, 'a');
    for (int i = 0; i < N; i++) {
        X.at(i) = S.at(i);
    }
    string Y(N, 'a');
    for (int i = 0; i < N; i++) {
        Y.at(i) = S.at(N+i);
    }
    
    for (int i = 0; i < Q; i++) {
        f(X, Y, T.at(i), A.at(i)-1, B.at(i)-1, N);
    }

    cout << X << Y << endl;
}