#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 200100
#define MOD 1000000007 //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>

vector<pii>e[N];
int a[N];
bool used[N];

void dfs(int k,int pc,int ec) {
	bool v = true;
	used[k] = true;
	if ((a[k] == -1) && (ec != pc))a[k] = ec;
	int sz = e[k].size();
	rep(i, sz) {
		if (!used[e[k][i].first]) {
			if ((a[k] == -1) && (e[k][i].second != pc))a[k] = e[k][i].second;
			dfs(e[k][i].first, a[k], e[k][i].second);
		}
	}
	return;
}



int main() {
	int n, m;
	int x, y, z;
	cin >> n >> m;
	rep(i, m) {
		cin >> x >> y >> z;
		x--;
		y--;
		e[x].pb({ y,z });
		e[y].pb({ x,z });
	}
	rep(i, n) {
		used[i] = false;
		a[i] = -1;
	}
	dfs(0, -1, -1);
	rep2(i, 1, n)used[i] = false;
	rep(i, n) {
		if (a[i] >= 0)used[a[i]] = true;
	}
	rep2(i,1, n) {
		if (!used[i]) {
			x = i;
			break;
		}
	}
	rep(i, n) {
		if (a[i] < 0)a[i] = x;
	}
	rep(i, n)cout << a[i] << endl;
	return 0;
}



#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define ENDL '\n'
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<x<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; ---"<<endl;for(auto c:vec)cout<<c<<" ";cout<<endl<<"----------------"<<endl;}
inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;}
template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;}
template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;}
const ll INF = (1LL<<30)-1;
const ll INFLL = (1LL<<62)-1;
const ld PI = 3.14159265358979323846L;

int main() {
    cout << fixed << setprecision(15);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n; cin>>n;
    string s; cin>>s;
    int q; cin>>q;
    int odd=0;
    vector<pair<int,int>> quer;
    while(q--) {
        int t,a,b; cin>>t>>a>>b;
        a--; b--;
        if(t==2) {odd++; continue;}
        if(odd%2==0) {
            quer.push_back({a,b});
        }
        else {
            if(a<=n-1) a+=n;
            else a-=n;
            if(b<=n-1) b+=n;
            else b-=n;
            quer.push_back({a,b});
        }
    }
    for(auto [a,b]:quer) {
        swap(s[a],s[b]);
    }
    if(odd%2==1) {
        string latter=s.substr(n), former=s.substr(0,n);
        s=latter+former;
    }
    cout<<s<<endl;
}