#pragma comment(linker, "/STACK:64000000")
#include <algorithm>
#include <memory.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define prev privet1
#define next privet2
#define y1 privet3
#define rank privet4
#define left privet5
#define right privet6
#define y0 privet7
const double pi = 3.141592653589793238;
void ensureLimit(long long n, long long l, long long r)
{
assert(l <= n && n <= r);
}
struct Segment {
int l, r, x;
};
const int MAX_M = 300333;
const int MAX_N = MAX_M;
int o[MAX_M];
int intend[MAX_N];
int ans[MAX_N];
long long add[MAX_M];
bool known[MAX_M];
long long a[MAX_M];
long long sum[MAX_N];
long long oldSum[MAX_N];
vector<int> list[MAX_N];
Segment s[3333];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &o[i]);
list[o[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &intend[i]);
}
int k;
memset(add, 0, sizeof(add));
memset(known, false, sizeof(known));
memset(a, 0, sizeof(a));
memset(sum, 0, sizeof(sum));
scanf("%d", &k);
int cnt = 0;
int sz = ceil(sqrt(k) * 3.3);
for (int i = 1; i <= k; i++) {
cnt++;
scanf("%d%d%d", &s[cnt].l, &s[cnt].r, &s[cnt].x);
if (i % sz == 0 || i == k) {
for (int j = 1; j <= n; j++) {
oldSum[j] = sum[j];
}
for (int j = 1; j <= cnt; j++) {
add[s[j].l] += s[j].x;
if (s[j].l <= s[j].r) {
add[s[j].r + 1] -= s[j].x;
}
}
long long curAdd = 0;
for (int j = 1; j <= m; j++) {
curAdd += add[j];
add[j] = 0;
if (known[o[j]]) continue;
sum[o[j]] += curAdd;
}
for (int j = 1; j <= cnt; j++) {
if (s[j].l > s[j].r) {
add[s[j].r + 1] -= s[j].x;
}
}
curAdd += add[m + 1];
for (int j = 1; j <= m; j++) {
curAdd += add[j];
add[j] = 0;
if (known[o[j]]) continue;
sum[o[j]] += curAdd;
}
add[m + 1] = 0;
int x;
for (int j = 1; j <= n; j++) {
if (known[j]) continue;
if (sum[j] >= intend[j]) {
known[j] = true;
for (int u = 1; u <= cnt && ans[j] == 0; u++) {
for (int y = 0; y < list[j].size(); y++) {
x = list[j][y];
if (s[u].l <= s[u].r) {
if (x >= s[u].l && x <= s[u].r) {
oldSum[j] += s[u].x;
}
}
else if (s[u].l <= x || s[u].r >= x) {
oldSum[j] += s[u].x;
}
if (oldSum[j] >= intend[j]) {
ans[j] = i - cnt + u;
break;
}
}
}
}
}
cnt = 0;
}
}
for (int i = 1; i <= n; i++) {
if (ans[i] > 0) {
printf("%d\n", ans[i]);
}
else printf("NIE\n");
}
}
I3ByYWdtYSBjb21tZW50KGxpbmtlciwgIi9TVEFDSzo2NDAwMDAwMCIpCiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxtZW1vcnkuaD4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjYXNzZXJ0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIHByZXYgcHJpdmV0MQojZGVmaW5lIG5leHQgcHJpdmV0MgojZGVmaW5lIHkxIHByaXZldDMKI2RlZmluZSByYW5rIHByaXZldDQKI2RlZmluZSBsZWZ0IHByaXZldDUKI2RlZmluZSByaWdodCBwcml2ZXQ2CiNkZWZpbmUgeTAgcHJpdmV0NwoKY29uc3QgZG91YmxlIHBpID0gMy4xNDE1OTI2NTM1ODk3OTMyMzg7Cgp2b2lkIGVuc3VyZUxpbWl0KGxvbmcgbG9uZyBuLCBsb25nIGxvbmcgbCwgbG9uZyBsb25nIHIpCnsKICAgIGFzc2VydChsIDw9IG4gJiYgbiA8PSByKTsKfQoKc3RydWN0IFNlZ21lbnQgewogICAgaW50IGwsIHIsIHg7Cn07CgoKY29uc3QgaW50IE1BWF9NID0gMzAwMzMzOwpjb25zdCBpbnQgTUFYX04gPSBNQVhfTTsKCmludCBvW01BWF9NXTsKaW50IGludGVuZFtNQVhfTl07CmludCBhbnNbTUFYX05dOwpsb25nIGxvbmcgYWRkW01BWF9NXTsKYm9vbCBrbm93bltNQVhfTV07CmxvbmcgbG9uZyBhW01BWF9NXTsKbG9uZyBsb25nIHN1bVtNQVhfTl07CmxvbmcgbG9uZyBvbGRTdW1bTUFYX05dOwp2ZWN0b3I8aW50PiBsaXN0W01BWF9OXTsKClNlZ21lbnQgc1szMzMzXTsKCgppbnQgbWFpbigpIHsKICAgIGludCBuLCBtOwogICAgc2NhbmYoIiVkJWQiLCAmbiwgJm0pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJm9baV0pOwogICAgICAgIGxpc3Rbb1tpXV0ucHVzaF9iYWNrKGkpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJmludGVuZFtpXSk7CiAgICB9CiAgICBpbnQgazsKICAgIG1lbXNldChhZGQsIDAsIHNpemVvZihhZGQpKTsKICAgIG1lbXNldChrbm93biwgZmFsc2UsIHNpemVvZihrbm93bikpOwogICAgbWVtc2V0KGEsIDAsIHNpemVvZihhKSk7CiAgICBtZW1zZXQoc3VtLCAwLCBzaXplb2Yoc3VtKSk7CiAgICBzY2FuZigiJWQiLCAmayk7CiAgICBpbnQgY250ID0gMDsKICAgIGludCBzeiA9IGNlaWwoc3FydChrKSAqIDMuMyk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKICAgICAgICBjbnQrKzsKICAgICAgICBzY2FuZigiJWQlZCVkIiwgJnNbY250XS5sLCAmc1tjbnRdLnIsICZzW2NudF0ueCk7CiAgICAgICAgaWYgKGkgJSBzeiA9PSAwIHx8IGkgPT0gaykgewogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBuOyBqKyspIHsKICAgICAgICAgICAgICAgIG9sZFN1bVtqXSA9IHN1bVtqXTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBjbnQ7IGorKykgewogICAgICAgICAgICAgICAgYWRkW3Nbal0ubF0gKz0gc1tqXS54OwogICAgICAgICAgICAgICAgaWYgKHNbal0ubCA8PSBzW2pdLnIpIHsKICAgICAgICAgICAgICAgICAgICBhZGRbc1tqXS5yICsgMV0gLT0gc1tqXS54OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvbmcgbG9uZyBjdXJBZGQgPSAwOwogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyBqKyspIHsKICAgICAgICAgICAgICAgIGN1ckFkZCArPSBhZGRbal07CiAgICAgICAgICAgICAgICBhZGRbal0gPSAwOwogICAgICAgICAgICAgICAgaWYgKGtub3duW29bal1dKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIHN1bVtvW2pdXSArPSBjdXJBZGQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gY250OyBqKyspIHsKICAgICAgICAgICAgICAgIGlmIChzW2pdLmwgPiBzW2pdLnIpIHsKICAgICAgICAgICAgICAgICAgICBhZGRbc1tqXS5yICsgMV0gLT0gc1tqXS54OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGN1ckFkZCArPSBhZGRbbSArIDFdOwogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyBqKyspIHsKICAgICAgICAgICAgICAgIGN1ckFkZCArPSBhZGRbal07CiAgICAgICAgICAgICAgICBhZGRbal0gPSAwOwogICAgICAgICAgICAgICAgaWYgKGtub3duW29bal1dKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIHN1bVtvW2pdXSArPSBjdXJBZGQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYWRkW20gKyAxXSA9IDA7CiAgICAgICAgICAgIGludCB4OwogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBuOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmIChrbm93bltqXSkgY29udGludWU7CiAgICAgICAgICAgICAgICBpZiAoc3VtW2pdID49IGludGVuZFtqXSkgewogICAgICAgICAgICAgICAgICAgIGtub3duW2pdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBmb3IgKGludCB1ID0gMTsgdSA8PSBjbnQgJiYgYW5zW2pdID09IDA7IHUrKykgewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IGxpc3Rbal0uc2l6ZSgpOyB5KyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHggPSBsaXN0W2pdW3ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHNbdV0ubCA8PSBzW3VdLnIpICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHggPj0gc1t1XS5sICYmIHggPD0gc1t1XS5yKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9sZFN1bVtqXSArPSBzW3VdLng7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBpZiAoc1t1XS5sIDw9IHggfHwgc1t1XS5yID49IHgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvbGRTdW1bal0gKz0gc1t1XS54OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9sZFN1bVtqXSA+PSBpbnRlbmRbal0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbnNbal0gPSBpIC0gY250ICsgdTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBjbnQgPSAwOwogICAgICAgIH0KICAgIH0KICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGlmIChhbnNbaV0gPiAwKSB7CiAgICAgICAgICAgIHByaW50ZigiJWRcbiIsIGFuc1tpXSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgcHJpbnRmKCJOSUVcbiIpOwogICAgfQp9Cg==