#include<bits/stdc++.h> 
#define rg register 
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i ) 
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i ) 
#define i60 long long 
using namespace std ; 
const int N = 2e5+10 , skc = 998244353 ; 
int pre[N] , deg[N] , n , pi[N] ;  
queue <int> q ;  bool is[N] ; 
int f( int x ) { return pre[x] == x ? x : pre[x] = f(pre[x]) ; } 
void merge( int x , int y ) { 
  if( f(x) == f(y) ) return ; 
  pre[f(x)] = f(y) ; 
} 
signed main( ) { 
  ios::sync_with_stdio(false) ; 
  cin.tie(0) ; 
  cin >> n ; int x , y ; 
  fp( i , 1 , n ) pre[i] = i ; 
  fp( i , 1 , n ) cin >> x , pi[i] = x , merge( x , i ) , deg[x] ++ ;  
  fp( i , 1 , n ) if( !deg[i] ) q.push(i) ; 
  while( q.size() ) { 
    x = q.front() ; q.pop() ; y = pi[x] ; 
	deg[y] -- ; if( !deg[y] ) q.push(y) ; 
  } 
  int ans = 1 , tot = 0 ; 
  fp( i , 1 , n ) if( deg[i] ) is[f(i)] = 1 ; 
  fp( i , 1 , n ) tot += is[i] ; 
  fp( i , 1 , tot ) ans = 2ll * ans % skc ; 
  cout << (ans-1+skc)%skc << '\n' ; 
  return 0 ;  
} 
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
  int n, q;
  bool flip = false;
  string s;
  cin >> n >> s >> q;
  rep(i, q) {
    int t, a, b;
    cin >> t >> a >> b;
    a--; b--;

    if(t == 1) {
      if(flip) {
        if(a < n) {
          a += n;
        } else {
          a -= n;
        }
        if(b < n) {
          b += n;
        } else {
          b -= n;
        }
        auto tmp = s[a];
        s[a] = s[b];
        s[b] = tmp;
      } else {
        auto tmp = s[a];
        s[a] = s[b];
        s[b] = tmp;
      }
    } else {
      flip = !flip;
    }
  }

  if(flip) {
    cout << s.substr(n) + s.substr(0, n) << endl;
  } else {
    cout << s << endl;
  }
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}
