#include <iostream>
#include <cstring>

using namespace std;
typedef long long ll;
const int N = 105;
const int M = 25005;

ll a[N], b[N], t[N];
ll dp[N][M];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> t[i];
	}
	memset(dp, 0, sizeof dp);
	for (int i = 0; i < n; i++) {
		for (int z = 1; z < M; z++) {
			dp[i+1][z] = dp[i][z];
			if (b[i] == 0) {
				if (z-t[i] >= 0) {
					dp[i+1][z] = max(dp[i+1][z], dp[i+1][z-t[i]] + a[i]);
				}
			} else {
				ll fun = 0;
				for (int k = 1; ; k++) {
					int z2 = z-k*t[i];
					ll f2 = a[i] - (k-1)*(k-1)*b[i];
					if (z2 < 0 || f2 < 0) break;
					fun += f2;
					dp[i+1][z] = max(dp[i+1][z], dp[i][z-k*t[i]] + fun);
				}
			}
		}
	}
	int q; cin >> q;
	while (q--) {
		int tt; cin >> tt;
		cout << dp[n][tt] << endl;
	}
}