#include <bits/stdc++.h>

#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int N,Q; string S; cin >> N >> S >> Q;
	string sf = S.substr(0, N);
	string sb = S.substr(N, N);
	rep(i,Q)
	{
		int t,a,b; cin>>t>>a>>b;
		a--; b--;
		if (t==1)
		{
			if (b < N)
				swap(sf[a], sf[b]);
			else if (a >= N)
				swap(sb[a-N], sb[b-N]);
			else
				swap(sf[a], sb[b-N]);
		}
		if (t==2) swap(sf, sb);
	}
	cout << sf << sb << "\n";
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	int ans = INF;
	int a = INF, b = INF;
	vector<int> A(N), B(N);
	REP(i, N) scanf("%d %d", &A[i], &B[i]), chmin(ans, A[i] + B[i]);
	REP(i, N) REP(j, N) if (i != j) chmin(ans, max(A[i], B[j]));
	cout << ans << endl;
}