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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define que pair<pii,int>

int N, M, Q;
int X[200010][3];
int O[200010], P[200010];
vector<que> V;
int ans[200010][2];
int A[3][3];
int now = 0;

void calc(int a[3][3], int b[3][3])
{
    int ret[3][3] = {0};
    rep(i, 3)rep(j, 3)rep(k, 3)
    {
        ret[i][j] += a[i][k] * b[k][j];
    }
    rep(i, 3)rep(j, 3)A[i][j] = ret[i][j];
}

void update()
{
    int o = O[now];
    int p = P[now];
    if(o == 1)
    {
        int B[3][3] = {{ 0, 1, 0},
                       {-1, 0, 0},
                       { 0, 0, 1}};
        calc(B, A);
    }
    else if(o == 2)
    {
        int B[3][3] = {{ 0,-1, 0},
                       { 1, 0, 0},
                       { 0, 0, 1}};
        calc(B, A);
    }
    else if(o == 3)
    {
        int B[3][3] = {{-1, 0,2*p},
                       { 0, 1, 0},
                       { 0, 0, 1}};
        calc(B, A);
    }
    else if(o == 4)
    {
        int B[3][3] = {{ 1, 0, 0},
                       { 0,-1,2*p},
                       { 0, 0, 1}};
        calc(B, A);
    }

    now++;
}

void unit(int tk_id, int id)
{
    ans[id][0] = X[tk_id][0] * A[0][0] + X[tk_id][1] * A[0][1] + A[0][2];
    ans[id][1] = X[tk_id][0] * A[1][0] + X[tk_id][1] * A[1][1] + A[1][2];
}

signed main()
{
    A[0][0] = A[1][1] = A[2][2] = 1;
    cin >> N;
    rep(i, N)
    {
        cin >> X[i][0] >> X[i][1];
        X[i][2] = 1;
    }
    cin >> M;
    rep(i, M)
    {
        cin >> O[i];
        if(O[i] > 2)cin >> P[i];
    }
    cin >> Q;
    rep(i, Q)
    {
        int a, b;
        cin >> a >> b;
        V.push_back({{a, b-1}, i});
    }

    sort(V.begin(), V.end());

    for(auto e : V)
    {
        int op_id = e.first.first;
        while(now < op_id)update();
        unit(e.first.second, e.second);
    }

    rep(i, Q)
    {
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007 
#define float double
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
const int N = 1e6+9;
int fact[N], invfact[N];
inline int add(int x, int y) { x += y; return x % mod;}
inline int sub(int x, int y) { x -= y; x %= mod; x += mod; return x % mod;}
inline int mul(int x, int y) { return  (x * y) % mod;}
inline int powr(int a, int b) {
	int x = 1 % mod;
	b %= (mod - 1);
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return powr(a, mod - 2);}
void pre() {
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for (int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k) {
    if(k == 0)
        return 1;
	if (n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int power(int x, int y, int m)
{
    if(y == 0)
        return 1;
    int temp = power(x,y/2,m);
    temp = ((temp%m) * (temp%m))%m;
    if(y%2 == 1)
        temp =  ((x%m) * (temp%m))%m;
    return temp;
}
// int dp[5009][5009];
bool isPalindrome(string str) {
  int i = 0, j = str.size() - 1;
 
  // traversing from both the ends
  while (i < j)
 
    // not palindrome
    if (str[i++] != str[j--])
      return false;
 
  // palindrome
  return true;
}
 
// function to remove all the palindromic words
// from the given sentence
string removePalinWords(string str) {
 
  // 'final_str' to store the final string and
  // 'word' to one by one store each word of 'str'
  string final_str = "", word = "";
 
  // add space at the end of 'str'
  str = str + " ";
  int n = str.size();
 
  // traversing 'str'
  for (int i = 0; i < n; i++) {
 
    // accumulating characters of the current word
    if (str[i] != ' ')
      word = word + str[i];
 
    else {
 
      // if 'word' is not palindrome then a
      // add it to 'final_str'
      if (!(isPalindrome(word)))
        final_str += word + " ";
 
      // reset
      word = "";
    }
  }
 
  // required final string
  return final_str;
}

void solve()
{
    int t = 1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
        string s;
        cin>>s;
        int n = s.size();
        deque<char> que;
        int c = 0;

        for(int i=0;i<n;i++)
        {
            if(s[i] == 'R')
                c = (c+1)%2;
            else
            {
                if(c == 0)
                {
                    if(que.size() != 0)
                    {
                        char ch = *que.rbegin();
                        if(ch == s[i])
                            que.erase(que.end());
                        else
                            que.push_back(s[i]);
                    }
                    else
                        que.push_back(s[i]);
                }
                else
                {
                    if(que.size() != 0)
                    {
                        char ch = *que.begin();
                        if(ch == s[i])
                            que.erase(que.begin());
                        else
                            que.push_front(s[i]);
                    }
                    else
                        que.push_front(s[i]);
                }
            }

        }

        string temp = "";
        for(auto it : que)
            temp.push_back(it);

        if(c == 1)
            reverse(temp.begin(),temp.end());
        
        cout<<temp;
    }    

}

int32_t main(){

    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    solve();
    return 0;
}
