#include<bits/stdc++.h> 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;
#define rq(x, y) range_query(1, 0, n, x, y)
#define ru(x, y, val) range_update(1, 0, n, x, y, val)
typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
  ((cout << args << ' '), ...);
  cout << '\n';
}
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e5 + 5;
const char nl = '\n';      
const ll INF = 2e18 + 5; 
int n;
ll x;
int res(int y, int re){
  if(y < 0){
    y += re;
  }
  assert(y >= 0);
  return y;
}
void solve(){
  cin >> n >> x; 
  vi a(n);
  for(int& it : a){
    cin >> it;
  }
  ll ans = INF;
  for(int i = 1; i <= n; i++){
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(i, vector<ll>(i + 1, -INF)));
    // dp[i][j][k] elemento i, con j de modulo con k elementos
    for(int j = 0; j < i; j++)
      dp[0][j][0] = 0;
    for(int l = 1; l <= i; l++){  
      for(int j = l; j <= n; j++){
        for(int k = 0; k < i; k++){
          // if(j < l) continue;
          dp[j][k][l] = dp[j - 1][k][l];
          if((dp[j - 1][res(k - (a[j - 1] % i), i)][l - 1]) % i == res(k - (a[j - 1] % i), i))
            dp[j][k][l] = max(dp[j - 1][res(k - (a[j - 1] % i), i)][l - 1] + a[j - 1], dp[j][k][l]);
          // dbg(j, k, l, dp[j][k][l]);
        }
      }
    }
    if(dp[n][x % i][i] > 0){
      // dbg(i, x%i, dp[n][x%i][i]);
      ans = min(ans, (x - dp[n][x % i][i]) / i);
    }
  }
  cout << ans << '\n';
}
int main(){
  cpu();
  int __ = 1;
  // cin >> __;
  while(__--){
    solve();
  }
  return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N;
    cin >> N;
    vll X(N), Y(N);
    rep(i, N) cin >> X[i] >> Y[i];
    ll M;
    cin >> M;
    vvll op(M, vll(2, 0));
    rep(i, M){
        cin >> op[i][0];
        if(op[i][0]>=3) cin >> op[i][1];
    }
    ll Q;
    cin >> Q;
    vll A(Q), B(Q);
    rep(i, Q) cin >> A[i] >> B[i];

    ll a = 1, b = 0, c = 0;
    ll d = 0, e = 1, f = 0;

    vll as = {a}, bs = {b}, cs = {c}, ds = {d}, es = {e}, fs = {f};

    rep(m, M){
        switch(op[m][0]){
            case 1:{
                ll u = a, v = b, w = c;
                a = d;
                b = e;
                c = f;
                d = -u;
                e = -v;
                f = -w;
                break;
            }
            case 2:{
                ll u = a, v = b, w = c;
                a = -d;
                b = -e;
                c = -f;
                d = u;
                e = v;
                f = w;
                break;
            }
            case 3:{
                a = -a;
                b = -b;
                c = -c + 2*op[m][1];
                break;
            }
            case 4:{
                d = -d;
                e = -e;
                f = -f + 2*op[m][1];
                break;
            }
        }
        as.push_back(a);
        bs.push_back(b);
        cs.push_back(c);
        ds.push_back(d);
        es.push_back(e);
        fs.push_back(f);
    }

    rep(q, Q){
        ll x = as[A[q]]*X[B[q]-1] + bs[A[q]]*Y[B[q]-1] + cs[A[q]];
        ll y = ds[A[q]]*X[B[q]-1] + es[A[q]]*Y[B[q]-1] + fs[A[q]];
        cout << x << " " << y << endl;
    }
}
