#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n, m, k;
int owner[MAXN];
long long target[MAXN];
int L[MAXN], R[MAXN], A[MAXN];
vector<int> sectors[MAXN];
struct Bit {
long long bit[MAXN];
int sz;
void init(int n) {
sz = n;
for (int idx = 0; idx <= sz + 1; idx++) bit[idx] = 0;
}
void update(int idx, long long val) {
for (; idx <= sz; idx += idx & -idx) bit[idx] += val;
}
void rangeUpdate(int l, int r, long long val) {
update(l, val);
update(r + 1, -val);
}
long long query(int idx) {
long long s = 0;
for (; idx > 0; idx -= idx & -idx) s += bit[idx];
return s;
}
};
Bit bit;
void applyEvent(int idx) {
if (L[idx] <= R[idx]) {
bit.rangeUpdate(L[idx], R[idx], A[idx]);
} else {
bit.rangeUpdate(L[idx], m, A[idx]);
bit.rangeUpdate(1, R[idx], A[idx]);
}
}
int lo[MAXN], hi[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int idx = 1; idx <= m; idx++) {
cin >> owner[idx];
sectors[owner[idx]].push_back(idx);
}
for (int idx = 1; idx <= n; idx++) cin >> target[idx];
cin >> k;
for (int idx = 1; idx <= k; idx++) cin >> L[idx] >> R[idx] >> A[idx];
for (int idx = 1; idx <= n; idx++) {
lo[idx] = 1;
hi[idx] = k + 1;
}
int rounds = (int)ceil(log2(k + 2)) + 1;
for (int iter = 0; iter < rounds; iter++) {
vector<vector<int>> buckets(k + 2);
bool anyActive = false;
for (int idx = 1; idx <= n; idx++) {
if (lo[idx] < hi[idx]) {
int mid = (lo[idx] + hi[idx]) / 2;
buckets[mid].push_back(idx);
anyActive = true;
}
}
if (!anyActive) break;
bit.init(m);
for (int t = 1; t <= k; t++) {
applyEvent(t);
for (int country : buckets[t]) {
long long got = 0;
for (int sec : sectors[country]) {
got += bit.query(sec);
if (got >= target[country]) break;
}
if (got >= target[country]) hi[country] = t;
else lo[country] = t + 1;
}
}
for (int country : buckets[k + 1]) lo[country] = k + 1;
}
for (int idx = 1; idx <= n; idx++) {
if (lo[idx] > k) cout << "NIE\n";
else cout << lo[idx] << "\n";
}
return 0;
}