#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <random>

#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

struct Progress {
    ll tp, cur, y;

    bool operator<(Progress const &p) const {
        return cur < p.cur;
    }
};

void solve() {
    int k;
    cin >> k;

    multiset<Progress> s;
    ll a, b, c;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b >> c;
        s.insert({a, b, c});
    }

    vector<ll> ans(1'000'001);
    for (int i = 0; i <= 1'000'000; ++i) {
        ans[i] = s.begin()->cur;

        Progress z = *s.begin();
        s.erase(s.begin());
        if (z.tp == 1) z.cur += z.y;
        else z.cur *= z.y;

        s.insert(z);
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> k;
        cout << ans[k] << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}