#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
  ll p, q, r;
  ll inf = 1e8 + 7;
  inf = inf * inf;
  p = -inf;
  q = inf;
  r = 0;
  int N;
  cin >> N;
  for (int i = 0; i < N; i ++) {
    ll a, t;
    cin >> a >> t;
    ll al, bt, gm;
    if (t == 1) {
      gm = a;
      al = -inf;
      bt = inf;
    }
    if (t == 2) {
      al = a;
      bt = inf;
      gm = 0;
    }
    if (t == 3) {
      bt = a;
      al = -inf;
      gm = 0;
    }
    ll nep = max(al, min(p + gm, bt));
    ll neq = min(q + gm, bt);
    ll ner = r + gm;
    p = nep;
    q = neq;
    r = ner;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i ++) {
    ll x;
    cin >> x;
    cout << max(p, min(x + r, q)) << endl;
  }
}
#include <bits/stdc++.h>
 
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);
 
using namespace std;

const int mod = 998244353;

struct Mint {
    ll v; explicit operator ll() const { return v; }
    Mint() { v = 0; }
    Mint(ll _v) { 
        v = (-mod < _v && _v < mod) ? _v : _v % mod;
        if (v < 0) v += mod;
    }
    friend bool operator==(const Mint& a, const Mint& b) { return a.v == b.v; }
    friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
    friend bool operator<(const Mint& a, const Mint& b) { return a.v < b.v; }
   
    Mint& operator+=(const Mint& m) { if ((v += m.v) >= mod) v -= mod; return *this; }
    Mint& operator-=(const Mint& m) { if ((v -= m.v) < 0) v += mod; return *this; }
    Mint& operator*=(const Mint& m) { v = v*m.v%mod; return *this; }
    Mint& operator/=(const Mint& m) { return (*this) *= inv(m); }

    friend Mint pow(Mint a, ll p) {
        Mint ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans;
    }
    
    friend Mint inv(const Mint& a) { assert(a.v != 0); return pow(a, mod-2); }

    Mint operator-() const { return Mint(-v); }
    Mint& operator++() { return *this += 1; }
    Mint& operator--() { return *this -= 1; }
    Mint operator++(int) { Mint temp; temp.v = v++; return temp; }
    Mint operator--(int) { Mint temp; temp.v = v--; return temp; }

    friend Mint operator+(Mint a, const Mint& b) { return a += b; }
    friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
    friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
    friend Mint operator/(Mint a, const Mint& b) { return a /= b; }

    friend ostream& operator<<(ostream& os, const Mint& m) {
        os << m.v; return os;
    }

    friend istream& operator>>(istream& is, Mint& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};

const int N = 200000 + 100;

Mint fact[N];

int ff[N];

void pre() {
    fact[0] = Mint(1);
    for (int i = 1; i < N; i++) fact[i] = Mint(i) * fact[i - 1];

    for (int i = 2; i < N; i++) {
        if (!ff[i]) {
            for (int j = i; j < N; j += i) {
                if (!ff[j]) ff[j] = i;
            }
        }
    }
}

Mint ncr(int n, int r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] / (fact[n - r] * fact[r]);
}

void solve() {
    int n, m;
    cin >> n >> m;

    Mint ans = 0, ans2 = 0;

    // vector<Mint> dp(m + 1, 1);
    // for (int itr = 2; itr <= n; itr++) {
    //     vector<Mint> ndp(m + 1, 0);
    //     for (int i = 1; i <= m; i++) {
    //         for (int j = i; j <= m; j += i) {
    //             ndp[j] += dp[i];
    //         }
    //     }

    //     dp.swap(ndp);
    // }

    for (ll i = 1; i <= m; i++) {
        ll x = i;
        Mint curr = 1;
        while (x > 1) {
            int cnt = 0;
            int f = ff[x];
            while (x % f == 0) {
                x /= f;
                cnt++;
            }
            curr *= ncr(cnt + n - 1, n - 1);
        }
        ans += curr;
    }

    cout << ans << "\n";
}

int main() {
    FASTIO;
    PRECISION;

    pre();

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; i++) {
        solve();
    }
}