#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;
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+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIHByZXYgcHJpdmV0MQojZGVmaW5lIG5leHQgcHJpdmV0MgojZGVmaW5lIHkxIHByaXZldDMKI2RlZmluZSByYW5rIHByaXZldDQKI2RlZmluZSBsZWZ0IHByaXZldDUKI2RlZmluZSByaWdodCBwcml2ZXQ2CiNkZWZpbmUgeTAgcHJpdmV0NwoKY29uc3QgZG91YmxlIHBpID0gMy4xNDE1OTI2NTM1ODk3OTMyMzg7Cgp2b2lkIGVuc3VyZUxpbWl0KGxvbmcgbG9uZyBuLCBsb25nIGxvbmcgbCwgbG9uZyBsb25nIHIpCnsKICAgIGFzc2VydChsIDw9IG4gJiYgbiA8PSByKTsKfQoKc3RydWN0IFNlZ21lbnQgewogICAgaW50IGwsIHIsIHg7Cn07CgoKY29uc3QgaW50IE1BWF9NID0gMzAwMzMzOwpjb25zdCBpbnQgTUFYX04gPSBNQVhfTTsKCmludCBvW01BWF9NXTsKaW50IGludGVuZFtNQVhfTl07CmludCBhbnNbTUFYX05dOwpsb25nIGxvbmcgYWRkW01BWF9NXTsKYm9vbCBrbm93bltNQVhfTV07CmxvbmcgbG9uZyBhW01BWF9NXTsKbG9uZyBsb25nIHN1bVtNQVhfTl07CmxvbmcgbG9uZyBvbGRTdW1bTUFYX05dOwp2ZWN0b3I8aW50PiBsaXN0W01BWF9OXTsKClNlZ21lbnQgc1szMzMzXTsKCgppbnQgbWFpbigpIHsKICAgIGludCBuLCBtOwogICAgc2NhbmYoIiVkJWQiLCAmbiwgJm0pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJm9baV0pOwogICAgICAgIGxpc3Rbb1tpXV0ucHVzaF9iYWNrKGkpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJmludGVuZFtpXSk7CiAgICB9CiAgICBpbnQgazsKICAgIHNjYW5mKCIlZCIsICZrKTsKICAgIGludCBjbnQgPSAwOwogICAgaW50IHN6ID0gY2VpbChzcXJ0KGspICogMy4zKTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGs7IGkrKykgewogICAgICAgIGNudCsrOwogICAgICAgIHNjYW5mKCIlZCVkJWQiLCAmc1tjbnRdLmwsICZzW2NudF0uciwgJnNbY250XS54KTsKICAgICAgICBpZiAoaSAlIHN6ID09IDAgfHwgaSA9PSBrKSB7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG47IGorKykgewogICAgICAgICAgICAgICAgb2xkU3VtW2pdID0gc3VtW2pdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IGNudDsgaisrKSB7CiAgICAgICAgICAgICAgICBhZGRbc1tqXS5sXSArPSBzW2pdLng7CiAgICAgICAgICAgICAgICBpZiAoc1tqXS5sIDw9IHNbal0ucikgewogICAgICAgICAgICAgICAgICAgIGFkZFtzW2pdLnIgKyAxXSAtPSBzW2pdLng7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG9uZyBsb25nIGN1ckFkZCA9IDA7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG07IGorKykgewogICAgICAgICAgICAgICAgY3VyQWRkICs9IGFkZFtqXTsKICAgICAgICAgICAgICAgIGFkZFtqXSA9IDA7CiAgICAgICAgICAgICAgICBpZiAoa25vd25bb1tqXV0pIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgc3VtW29bal1dICs9IGN1ckFkZDsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBjbnQ7IGorKykgewogICAgICAgICAgICAgICAgaWYgKHNbal0ubCA+IHNbal0ucikgewogICAgICAgICAgICAgICAgICAgIGFkZFtzW2pdLnIgKyAxXSAtPSBzW2pdLng7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3VyQWRkICs9IGFkZFttICsgMV07CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG07IGorKykgewogICAgICAgICAgICAgICAgY3VyQWRkICs9IGFkZFtqXTsKICAgICAgICAgICAgICAgIGFkZFtqXSA9IDA7CiAgICAgICAgICAgICAgICBpZiAoa25vd25bb1tqXV0pIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgc3VtW29bal1dICs9IGN1ckFkZDsKICAgICAgICAgICAgfQogICAgICAgICAgICBhZGRbbSArIDFdID0gMDsKICAgICAgICAgICAgaW50IHg7CiAgICAgICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG47IGorKykgewogICAgICAgICAgICAgICAgaWYgKGtub3duW2pdKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIGlmIChzdW1bal0gPj0gaW50ZW5kW2pdKSB7CiAgICAgICAgICAgICAgICAgICAga25vd25bal0gPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIGZvciAoaW50IHUgPSAxOyB1IDw9IGNudCAmJiBhbnNbal0gPT0gMDsgdSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaW50IHkgPSAwOyB5IDwgbGlzdFtqXS5zaXplKCk7IHkrKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgeCA9IGxpc3Rbal1beV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc1t1XS5sIDw9IHNbdV0ucikgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoeCA+PSBzW3VdLmwgJiYgeCA8PSBzW3VdLnIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb2xkU3VtW2pdICs9IHNbdV0ueDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGlmIChzW3VdLmwgPD0geCB8fCBzW3VdLnIgPj0geCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9sZFN1bVtqXSArPSBzW3VdLng7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob2xkU3VtW2pdID49IGludGVuZFtqXSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFuc1tqXSA9IGkgLSBjbnQgKyB1OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGNudCA9IDA7CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgaWYgKGFuc1tpXSA+IDApIHsKICAgICAgICAgICAgcHJpbnRmKCIlZFxuIiwgYW5zW2ldKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBwcmludGYoIk5JRVxuIik7CiAgICB9Cn0K