#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(lli i=(lli)a;i<=(lli)b;i++)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define pi 3.14159265359
#define gc getchar
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define eb emplace_back
// #define lli int
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli n,m,P[300009],S[300009],ans[300009];
pll Q[300009];
vl A[300009];
struct SegTree
{
vl v;
SegTree(lli n):v(4*n){}
SegTree(){}
void rangeupdate(lli ind,lli a,lli b,lli l,lli r,lli x)
{
if(a>b || l>r || r<a || l>b) return;
if(l<=a && r>=b) {v[ind]+=x;return;}
lli mid=(a+b)/2;
rangeupdate(ind<<1,a,mid,l,r,x);
rangeupdate((ind<<1)+1,mid+1,b,l,r,x);
}
lli query(lli ind,lli a,lli b,lli qin)
{
// pr(ind,a,b,qin);
if(a>b || qin<a || qin>b) return 0;
if(a==b) return v[ind];
lli mid=(a+b)/2;
return v[ind]+query(ind<<1,a,mid,qin)+query((ind<<1)+1,mid+1,b,qin);
}
};
SegTree T;
void apply(lli ind,lli sign)
{
// pr(ind,sign,Q[ind],S[ind]);
if(Q[ind].X<=Q[ind].Y)
T.rangeupdate(1,1,m,Q[ind].X,Q[ind].Y,sign*S[ind]);
else
{
T.rangeupdate(1,1,m,1,Q[ind].Y,sign*S[ind]);
T.rangeupdate(1,1,m,Q[ind].X,m,sign*S[ind]);
}
// FOR(i,1,5) pr(T.query(1,1,m,i));
}
lli query(lli ind)
{
lli ret = T.query(1,1,m,ind);
// pr(ind,ret);
return ret;
}
void solve(lli l,lli r,vl& v,lli nq)
{
// pr(l,r,v,nq);
if(v.empty() || l>r) return;
lli mid=(l+r)/2;
if(nq<mid)
FOR(i,nq+1,mid)
apply(i,1);
else
FOR(i,mid+1,nq)
apply(i,-1);
vl lv,rv;
for(lli i:v)
{
lli sum=0;
for(lli j:A[i])
sum+=query(j);
if(sum>=P[i])
{ans[i]=min(ans[i],mid);lv.pb(i);}
else rv.pb(i);
}
if(l!=r){solve(l,mid,lv,mid);
solve(mid+1,r,rv,mid);}
if(nq<mid)
FOR(i,nq+1,mid)
apply(i,-1);
else
FOR(i,mid+1,nq)
apply(i,1);
}
int main()
{
fastio;
lli a,k,l,r;vl v;
cin>>n>>m;
T=SegTree(m);
FOR(i,1,n)
ans[i]=inf;
FOR(i,1,m)
{
cin>>a;
A[a].pb(i);
}
FOR(i,1,n)
cin>>P[i];
cin>>k;
FOR(i,1,k)
{
cin>>l>>r>>a;
Q[i]=mp(l,r);
S[i]=a;
}
FOR(i,1,n) v.pb(i);
solve(1,k,v,0);
FOR(i,1,n)
if(ans[i]!=inf)
cout<<ans[i]<<endl;
else cout<<"NIE"<<endl;
}
I2luY2x1ZGU8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