#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <string.h>

#include <time.h>
#include <random>
#include <iomanip>
using namespace std;

#define ll long long
#define T 25005
#define N 105

ll a[N], b[N], t[N];

ll dp[2*T];

ll f(ll i, ll k) {
    ll res = a[i] - (k-1)*(k-1)*b[i];
    if (res < 0)
        return 0;
    return res;
}

void cp1to2(ll a[N], ll b[N], ll n) {
    for (ll i = 0; i < n; i++)
        b[i] = a[i];
}

void solve() {
    ll n;
    cin >> n;
    
    vector<pair<ll,ll> > constRides; //{fun, time}
    vector<pair<ll,ll> > rides; //{fun, time}
    
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> t[i];
        if (b[i] == 0)
            constRides.push_back({a[i],t[i]});
        else {
            ll k = 1;
            while (f(i,k) > 0) {
                rides.push_back({f(i,k), t[i]});
                k++;
            }
        }
    }
    
    dp[0] = 0;
    
    for (ll i = 0; i < T; i++) {
        for (ll j = 0; j < constRides.size(); j++) {
            dp[i+constRides[j].second] = max(dp[i+constRides[j].second], dp[i] + constRides[j].first);
        }
    }
    
    for (ll i = 0; i < rides.size(); i++) {
        for (ll j = T-1; j >= 0; j--) {
            dp[j+rides[i].second] = max(dp[j+rides[i].second], dp[j] + rides[i].first);
        }
    }
    
    ll q;
    cin >> q;
    for (ll i = 0; i < q; i++) {
        ll index;
        cin >> index;
        cout << dp[index] << endl;
    }
    
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    //    ll t;
    //    cin >> t;
    //    for (ll i = 0; i < t; i++) {
    //        solve();
    //    }
}