#define DEBUG 0
#define MAX_N 1000  // relvad
#define MAX_K 32  // taringud
#define MAX_R 100  // tahud
#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][MAX_R * MAX_K + 1][MAX_K + 1];
int t;

ll getprob(int j) {
	ll p = 0;
	for (int t1 = max(t - f[j], 0); t1 <= k[j] * r[j]; t1++) {
		p += dp[j][t1][k[j]];
	}
	return p;
}

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
			for (t = 1; t <= k[i] * r[i]; t++) {
				// silmade arv jargmisel taringul
				for (int r1 = 1; r1 <= r[i]; r1++) {
					if (t >= r1) {
						dp[i][t][j] += dp[i][t - r1][j - 1];
					}
				}
			}
		}
	}

	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 = getprob(j);
			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 << " " << bestnum << " / " << bestden << endl;
#endif // DEBUG
	}

	return 0;
}
