#define DEBUG 0
#define MAX_N 1000  // relvad
#define ll long long
#include <iostream>
using namespace std;

ll pow(int x, int p) {
	if (p == 0) return 1;
	if (p == 1) return x;

	ll tmp = pow(x, p / 2);
	if (p % 2 == 0) return tmp * tmp;
	else return x * tmp * tmp;
}

int k[MAX_N], r[MAX_N], f[MAX_N];
int dp[MAX_N][120000][2];
ll suf[MAX_N][120000];
int t;

int main() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> k[i] >> r[i] >> f[i];
	}

	for (int i = 0; i < n; i++) {
		dp[i][0][0] = 1;

		// taringute arv
		for (int j = 1; j <= k[i]; j++) {
			// variantide arv saada t silma
			dp[i][0][j % 2] = 0;
			for (t = 1; t <= r[i]; t++) {
				dp[i][t][j % 2] = dp[i][t - 1][j % 2] + dp[i][t - 1][(j - 1) % 2];
			}
			for (t = r[i] + 1; t <= k[i] * r[i]; t++) {
				dp[i][t][j%2] = dp[i][t - 1][j%2] + dp[i][t - 1][(j - 1) % 2] - dp[i][t - r[i] - 1][(j - 1) % 2];
			}
		}

		int kr = k[i] * r[i];
		suf[i][kr] = dp[i][kr][k[i] % 2];
		for (int j = k[i] * r[i] - 1; j >= 0; j--) {
			suf[i][j] = suf[i][j+1] + dp[i][j][k[i] % 2];
		}
	}

	//for (int i = 0; i < k[1] * r[1]; i++) {
	//	for (int j = 0; j <= k[1]; j++) {
	//		cout << dp[1][i][j] << " ";
	//	}
	//	cout << endl;
	//}

	for (int i = 0; i < q; i++) {
		cin >> t;
		int bestn = -1;
		ll bestnum = 0, bestden = 1000000;
		for (int j = 0; j < n; j++) {
			ll p = suf[j][max(t - f[j], 0)];
			ll c = pow(r[j], k[j]);

#if DEBUG
			cout << j + 1;
			cout << " " << p << " / " << c << " = " << (double)p / c << endl;
#endif // DEBUG

			if (p * bestden > c * bestnum) {
				bestden = c;
				bestnum = p;
				bestn = j;
			}
		}
		cout << bestn + 1 << endl;
#if DEBUG
		cout << t << " " << k[bestn] << " " << r[bestn] << " " << f[bestn] << " " << bestnum << " / " << bestden << endl;
#endif // DEBUG
	}

	return 0;
}
