#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 100002

int n;
int m;

vector<int> v;

vector<pair<int, int> > v1;
struct st {
    int c;
    int d;
    int k;
    st(int a, int b, int c_) {
        c = a;
        d = b;
        k = c_;
    }
};
vector<st> v2;

int gt(int a) {
    return lower_bound(v.begin(), v.end(), a) - v.begin();
}

vector<int> want[MAX];
vector<int> add[MAX];

int ap[MAX];
map<int, vector<pair<int, int> > > mp;
int main() {
    scanf("%d", &n);
    for (int i = 0;i < n;i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        v1.push_back(make_pair(a, b));
        v.push_back(a);
        v.push_back(b);
    }
    cin >> m;
    for (int i = 0;i < m;i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        v.push_back(a);
        v.push_back(b);
        v2.push_back(st(a, b, c));
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 0;i < v1.size();i++) {
        int a = gt(v1[i].first);
        v1[i].second = gt(v1[i].second);
        want[a].push_back(i);
    }
    for (int i = 0;i < v2.size();i++) {
        v2[i].c = gt(v2[i].c);
        v2[i].d = gt(v2[i].d);
        add[v2[i].c].push_back(i);
    }
    memset(ap, -1, sizeof(ap));
    for (int i = 0;i < v.size();i++) {
        for (int j = 0;j < add[i].size();j++) {
            int ind = add[i][j];
            mp[v2[ind].d].push_back(make_pair(ind, v2[ind].k));
        }
        while (mp.size() && (*mp.begin()).first < i) {
            mp.erase(mp.begin());
        }
        for (int j = 0;j < want[i].size();j++) {
            int ind = want[i][j];
            int r = v1[ind].second;
            auto ite = mp.lower_bound(r);
            if (ite == mp.end()) {
                puts("NO");
                return 0;
            }
            while (ite != mp.end()) {
                bool d = false;
                while ((*ite).second.size()) {
                    if ((*ite).second.back().second == 0) {
                        (*ite).second.pop_back();
                    }
                    else {
                        ap[ind] = (*ite).second.back().first;
                        (*ite).second.back().second--;
                        d = true;
                        break;
                    }
                }
                if (d == false) {
                    int v = (*ite).first;
                    ite++;
                    mp.erase(v);
                }
                else {
                    break;
                }
            }
            if (ite == mp.end()) {
                puts("NO");
                return 0;
            }
        }
    }
    puts("YES");
    for (int i = 0;i < n;i++) {
        if (i) {
            printf(" ");
        }
        printf("%d", ap[i] + 1);
    }
    puts("");
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 600002

int n;
int m;

vector<int> v;

vector<pair<int, int> > v1;
struct st {
    int c;
    int d;
    int k;
    st(int a, int b, int c_) {
        c = a;
        d = b;
        k = c_;
    }
};
vector<st> v2;

int gt(int a) {
    return lower_bound(v.begin(), v.end(), a) - v.begin();
}

vector<int> want[MAX];
vector<int> add[MAX];

int ap[MAX];
map<int, vector<pair<int, int> > > mp;
int main() {
    scanf("%d", &n);
    for (int i = 0;i < n;i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        v1.push_back(make_pair(a, b));
        v.push_back(a);
        v.push_back(b);
    }
    cin >> m;
    for (int i = 0;i < m;i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        v.push_back(a);
        v.push_back(b);
        v2.push_back(st(a, b, c));
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 0;i < v1.size();i++) {
        int a = gt(v1[i].first);
        v1[i].second = gt(v1[i].second);
        want[a].push_back(i);
    }
    for (int i = 0;i < v2.size();i++) {
        v2[i].c = gt(v2[i].c);
        v2[i].d = gt(v2[i].d);
        add[v2[i].c].push_back(i);
    }
    memset(ap, -1, sizeof(ap));
    for (int i = 0;i < v.size();i++) {
        for (int j = 0;j < add[i].size();j++) {
            int ind = add[i][j];
            mp[v2[ind].d].push_back(make_pair(ind, v2[ind].k));
        }
        while (mp.size() && (*mp.begin()).first < i) {
            mp.erase(mp.begin());
        }
        for (int j = 0;j < want[i].size();j++) {
            int ind = want[i][j];
            int r = v1[ind].second;
            auto ite = mp.lower_bound(r);
            if (ite == mp.end()) {
                puts("NO");
                return 0;
            }
            while (ite != mp.end()) {
                bool d = false;
                while ((*ite).second.size()) {
                    if ((*ite).second.back().second == 0) {
                        (*ite).second.pop_back();
                    }
                    else {
                        ap[ind] = (*ite).second.back().first;
                        (*ite).second.back().second--;
                        d = true;
                        break;
                    }
                }
                if (d == false) {
                    int v = (*ite).first;
                    ite++;
                    mp.erase(v);
                }
                else {
                    break;
                }
            }
            if (ite == mp.end()) {
                puts("NO");
                return 0;
            }
        }
    }
    puts("YES");
    for (int i = 0;i < n;i++) {
        if (i) {
            printf(" ");
        }
        printf("%d", ap[i] + 1);
    }
    puts("");
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;

struct song {
    int ix, l, r;
    bool operator< (const song& c) const {
        return r<c.r;
    }
}sng[100100];

struct actor {
    int ix, a, b, as;
    bool operator< (const actor& c) const {
        return b<c.b;
    }
}act[100100];

struct sst {
    int ix, l;
    bool operator< (const sst& c) const {
        return l<c.l;
    }
}im;

multiset<sst> sets;
multiset<sst>::iterator it;

int n, m, asg[100100];

int main(){
    int i, j, k;
    scanf("%d", &n);
    for(i=0; i<n; i++)scanf("%d%d", &sng[i].l, &sng[i].r), sng[i].ix=i+1;
    scanf("%d", &m);
    for(i=0; i<m; i++)scanf("%d%d%d", &act[i].a, &act[i].b, &act[i].as), act[i].ix=i+1;
    sort(sng, sng+n);
    sort(act, act+m);
    for(i=j=0; i<m; i++){
        for(; j<n; j++){
            if(sng[j].r > act[i].b)break;
            im.ix=sng[j].ix, im.l=sng[j].l;
            sets.insert(im);
        }
        for(k=0; k<act[i].as; k++){
            im.l=act[i].a;
            it=sets.lower_bound(im);
            if(it==sets.end())break;
            im=*it;
            asg[im.ix]=act[i].ix;
            sets.erase(it);
        }
    }
    for(i=1; i<=n; i++){
        if(!asg[i])break;
    }
    if(i<=n)puts("NO");
    else{
        puts("YES");
        for(i=1; i<=n; i++)printf("%d ", asg[i]);
    }
    return 0;
}


#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;

struct evt {
	int l, r, t, i, k;
	bool operator<(evt o) const {
		return l == o.l? t == o.t? i < o.i : t > o.t : l < o.l;
	}
};

const int MAXN = 1e6;

int N, M, r[MAXN];
vector<evt> e;

int main() {
	//freopen("A.in", "r", stdin);
	scanf("%d", &N);
	for(int i = 1, a, b; i <= N; i++) {
		scanf("%d%d", &a, &b);
		e.push_back({a, b, 0, i, 0});
	}
	scanf("%d", &M);
	for(int i = 1, c, d, k; i <= M; i++) {
		scanf("%d%d%d", &c, &d, &k);
		e.push_back({c, d, 1, i, k});
		e.push_back({d, c, -1, i, 0});
	}

	sort(e.begin(), e.end());
	multiset<evt> s;
	for(evt x: e) {
		if(x.t == 1)
			s.insert({x.r, 0, 0, x.i, x.k});
		if(x.t == 0) {
			auto i = s.lower_bound({x.r, 0, 0, 0, 0});
			if(i == s.end()) {
				puts("NO");
				return 0;
			}
			r[x.i] = i->i;
			if(i->k > 1)
				s.insert({i->l, 0, 0, i->i, i->k-1});
			s.erase(i);
		}
		if(x.t == -1) {
			auto i = s.find({x.l, 0, 0, x.i, x.k});
			if(i != s.end())
				s.erase(i);
		}
	}

	puts("YES");
	for(int i = 1; i <= N; i++)
		printf("%d ", r[i]);
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
using LL = long long;
using PII = pair<int,int>;

const int N = 200005;
int n, m;
struct Node {
	int i, x, y, k;
	bool operator <(const Node &rhs) const {
		return y<rhs.y;
	}
};
vector<Node> ns;
multiset<Node> S;
int ans[N];

int main() {
	scanf("%d", &n);
	FI(i,1,n) {
		int x, y; scanf("%d%d", &x, &y);
		ns.push_back({i,x,y,0});
	}
	scanf("%d", &m);
	FI(i,1,m) {
		int x, y, k; scanf("%d%d%d", &x, &y, &k);
		ns.push_back({i,x,y,k});
	}
	sort(ns.begin(), ns.end(), [](const Node &a, const Node &b) {
		return a.x!=b.x ? a.x<b.x : a.k>b.k;
			});
	for (auto &t: ns) {
		if (t.k) S.insert(t);
		else {
			auto p = S.lower_bound(t);
			if (p==S.end()) return !printf("NO\n");
			auto z = *p;
			S.erase(p);
			if (--z.k) S.insert(z);
			ans[t.i] = z.i;
		}
	}
	printf("YES\n");
	FI(i,1,n) printf("%d ", ans[i]);
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
using LL = long long;
using PII = pair<int,int>;

const int N = 200005;
int n, m;
struct Node {
	int i, x, y, k;
	bool operator <(const Node &rhs) const {
		return y < rhs.y;
	}
};
vector<Node> ns;
set<Node> S;
int ans[N];

int main() {
	scanf("%d", &n);
	FI(i,1,n) {
		int x, y; scanf("%d%d", &x, &y);
		ns.push_back({i,x,y,0});
	}
	scanf("%d", &m);
	FI(i,1,m) {
		int x, y, k; scanf("%d%d%d", &x, &y, &k);
		ns.push_back({i,x,y,k});
	}
	sort(ns.begin(), ns.end(), [](const Node &a, const Node &b) {
		return a.x!=b.x ? a.x<b.x : a.k>b.k;
			});
	for (auto &t: ns) {
		if (t.k) S.insert(t);
		else {
			auto p = S.lower_bound(t);
			if (p==S.end()) return !printf("NO\n");
			auto z = *p;
			S.erase(p);
			if (--z.k) S.insert(z);
			ans[t.i] = z.i;
		}
	}
	printf("YES\n");
	FI(i,1,n) printf("%d ", ans[i]);
}


#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265359
#endif // M_PI
#define endl "\n"
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int __i = 0; __i < (n); ++__i) cin >> a[__i];
#define GETM(a, n, m) for (int __i = 0; __i < (n); ++__i) for (int __j = 0; __j < m; ++__j) cin >> a[__i][__j];
#define PRINTM(a, n, m) for (int __i = 0; __i < (n); ++__i) { for (int __j = 0; __j < m; ++__j) cout << a[__i][__j] << " ";  cout << endl; };
#define PRINT(a, n) for (int __i = 0; __i < (n); ++__i) cout << a[__i] << " ";
#define IT(a) a.begin(), a.end()
#define CASE(a, s) cout << "Case #" << a << ": " << s << endl;
#define DEB(a) cout << #a << " = " << (a) << endl; cout.flush();
#define DEBA(a) for (auto __i: a) cout << __i << " "; cout << endl;
#define IFDEB(b, a) if (b) { cout << #a << " = " << a << endl; cout.flush(); }
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
typedef vector <vector <int>> VVI;
typedef pair <int, int> PII;
const int MOD = 1000000007;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;

struct Z
{
    LL l;
    LL r;
    LL i;
    int operator < (const Z &a) const
    {
        return r > a.r;
    }
};

struct Y
{
    LL l;
    LL r;
    LL k;
    LL i;
    int operator < (const Y &a) const
    {
        return r > a.r;
    }
};

template <class T> class SegmentTree
{
    int maxn = 1000000;
    vector <T> t;
    void build(const vector <T> &a, int v, int tl, int tr) {
        if (tl == tr) {
            t[v] = a[tl];
        } else {
            int tm = (tl + tr) / 2;
            build (a, v * 2 + 1, tl, tm);
            build (a, v * 2 + 2, tm + 1, tr);
            t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
        }
    }
    T sum(int v, int tl, int tr, int l, int r) {
        if (l > r) {
            return INT_MAX;
        }
        if (l == tl && r == tr) {
            return t[v];
        }
        int tm = (tl + tr) / 2;
        return min(sum (v * 2 + 1, tl, tm, l, min(r, tm)),
sum (v * 2 + 2, tm + 1, tr, max(l, tm + 1), r));
    }
    void update(int v, int tl, int tr, int pos, T new_val) {
        if (tl == tr) {
            t[v] = new_val;
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update (v * 2 + 1, tl, tm, pos, new_val);
            } else {
                update (v * 2 + 2, tm + 1, tr, pos, new_val);
            }
            t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
        }
    }
public:
    SegmentTree () {}
    SegmentTree (int n)
    {
        maxn = n;
        t.resize(4 * maxn);
    }
    SegmentTree (const vector <T> &a) {
        maxn = a.size();
        t.resize(4 * maxn);
        build(a, 0, 0, maxn - 1);
    }
    void update(int pos, T add)
    {
        update(0, 0, maxn - 1, pos, add);
    }
    T sum(int l, int r)
    {
        return sum(0, 0, maxn - 1, l, r);
    }
};

SegmentTree <int> t;

enum {GREATER = -1, LOWER = 1};

int bsearch_answer(int l, int r, int (*f)(int t))
{
    while (l < r) {
        int t = (l + r) / 2;
        int p = f(t);
        if (!p) {
            l = t;
            break;
        } else if (p > 0) {
            r = t;
        } else {
            l = t + 1;
        }
    }
    return l;
}

int start;
int lmin;

inline int f(int x)
{
    return t.sum(start, x) > lmin ? GREATER : LOWER;
}

int main()
{
    int n, m;
    cin >> n;
    vector <Z> v(n);
    FOR (i, 0, n) {
        cin >> v[i].l >> v[i].r;
        v[i].i = i;
    }
    cin >> m;
    vector <Y> w(m);
    FOR (i, 0, m) {
        cin >> w[i].l >> w[i].r >> w[i].k;
        w[i].i = i;
    }
    sort(IT(v), [] (const Z &a, const Z &b) { return a.l < b.l; });
    sort(IT(w), [] (const Y &a, const Y &b) { return a.r < b.r; });
    vector <int> ans(n, -1);
    vector <int> a(m + 1);
    FOR (i, 0, m) {
        a[i] = w[i].l;
    }
    a[m] = -1;
    t = SegmentTree <int> (a);
    for (auto i: v) {
        int j = lower_bound(IT(w), i.r, [](const Y &a, int b) { return a.r < b; }) - w.begin();
        start = j;
        lmin = i.l;
        int pos = bsearch_answer(j, m, f);
        if (pos == m) {
            cout << "NO";
            return 0;
        }
        --w[pos].k;
        ans[i.i] = w[pos].i;
        if (w[pos].k == 0) {
            t.update(pos, INT_MAX);
        }
    }
    cout << "YES" << endl;
    for (auto i: ans) {
        cout << i + 1 << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;

struct event {
	int id, type, l, r;
};

bool operator < (const event& a, const event& b) {
	if (a.l < b.l)
		return true;
	if (b.l < a.l)
		return false;
	return a.type < b.type;
}

int main() {
	vector<event> events;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		events.push_back({i, 1, a, b});
	}
	int m;
	cin >> m;
	vector<int> cnt(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b >> cnt[i];
		events.push_back({i, 0, a, b});
	}
	sort(events.begin(), events.end());
	set<pair<int, int>> s;
	vector<int> ans(n);
	for (auto e : events) {
		if (e.type == 0)
			s.insert({e.r, e.id});
		else {
			auto it = s.lower_bound({e.r, 0});
			if (it == s.end()) {
				cout << "NO" << endl;
				return 0;
			}
			ans[e.id] = it->second;
			cnt[it->second]--;
			if (cnt[it->second] == 0)
				s.erase(it);
		}
	}
	cout << "YES" << endl;
	for (int i = 0; i < n; i++)
		cout << ans[i] + 1 << ' ';
	cout << endl;
}


#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<vector>
#include<iostream>
#include<deque>
#include<queue>
#include<set>
#pragma comment(linker, "/STACK:102400000,102400000")
#define LL __int64
#define eps 1e-10
#define zero(x) ((x > +eps) - (x < -eps))
#define mem(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 99999999
#define MAX 200010
using namespace std;

struct NODE
{
    int a, b, k, id;
    bool operator < (const struct NODE & x)const
    {
        if(a == x.a)
        {
            return k > x.k;
        }
        return a < x.a;
    }
}nodes[MAX];

set<pair<int,int> > s;
int n, m;
int ans[MAX];

int main()
{
    while(~scanf("%d",&n))
    {
        s.clear();
        for(int i = 1; i <= n; i ++)
        {
            scanf("%d%d",&nodes[i].a,&nodes[i].b);
            nodes[i].id = i;
            nodes[i].k = -1;
        }
        scanf("%d",&m);
        for(int i = 1; i <= m; i ++)
        {
            scanf("%d%d%d",&nodes[n+i].a,&nodes[i+n].b,&nodes[i+n].k);
            nodes[i+n].id = i;
        }
        int sum = n + m;
        sort(nodes+1,nodes+1+sum);
        pair<int,int> temp;
        set<pair<int,int> >::iterator it;
        int f = 0;
        for(int i = 1; i <= sum; i ++)
        {
            if(nodes[i].k == -1)
            {
                if(s.empty())
                {
                    f = 1;
                    break;
                }
                else
                {
                    temp.first = nodes[i].b;
                    temp.second = nodes[i].k;
                    it = s.lower_bound(temp);
                    if(it == s.end())
                    {
                        f = 1;
                        break;
                    }
                    else
                    {
                        int x = it->second;
                        ans[nodes[i].id] = nodes[x].id;
                        nodes[x].k --;
                        if(!nodes[x].k)
                        {
                            s.erase(it);
                        }
                    }
                }
            }
            else
            {
                temp.first = nodes[i].b;
                temp.second = i;
                s.insert(temp);
            }
        }
        if(f)
        {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
        for(int i = 1; i <= n; i ++)
        {
            printf("%d ",ans[i]);
        }
        printf("\n");
    }
    return 0;
}


//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
struct GUGAN
{
	int s, e;
	int type;
	int idx, x;
	bool operator<(const GUGAN &p) const
	{
		return e < p.e;
	}
	GUGAN(){}
	GUGAN(int s, int e, int type, int idx, int x)
	{
		this->s=s, this->e=e, this->type=type, this->idx=idx, this->x=x;
	}
};

bool cmp(GUGAN p, GUGAN q)
{
	if(p.s != q.s) return p.s < q.s;
	return p.type < q.type;
}

vector<GUGAN> v;
multiset<GUGAN> s;

int dab[200000];

int main()
{
	int i, j, k;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		v.push_back(GUGAN(x, y, 2, i, -1));
	}
	scanf("%d", &m);
	for(i=0;i<m;i++)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		v.push_back(GUGAN(x, y, 1, i, z));
	}
	sort(v.begin(), v.end(), cmp);
	for(auto e : v)
	{
		if(e.type == 1) s.insert(e);
		else
		{
			auto it=s.lower_bound(GUGAN(0, e.e, 0, 0, 0));
			if(it == s.end()) return printf("NO"), 0;
			GUGAN u=*it;
			s.erase(it);
			u.x--;
			dab[e.idx]=u.idx;
			if(u.x != 0) s.insert(u);
		}
	}
	printf("YES\n");
	for(i=0;i<n;i++) printf("%d ", dab[i]+1);
	return 0;
}
//*/


//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <functional>
#define MOD 1000000007
#define MAX ((1<<30)-1)
#define MAX2 ((1ll<<62)-1)
#pragma warning(disable:4996)
using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
struct GUGAN
{
	int s, e;
	int type;
	int idx, x;
	bool operator<(const GUGAN &p) const
	{
		return e < p.e;
	}
	GUGAN(){}
	GUGAN(int s, int e, int type, int idx, int x)
	{
		this->s=s, this->e=e, this->type=type, this->idx=idx, this->x=x;
	}
};

bool cmp(GUGAN p, GUGAN q)
{
	if(p.s != q.s) return p.s < q.s;
	return p.type < q.type;
}

vector<GUGAN> v;
set<GUGAN> s;

int dab[200000];

int main()
{
	int i, j, k;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		v.push_back(GUGAN(x, y, 2, i, -1));
	}
	scanf("%d", &m);
	for(i=0;i<m;i++)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		v.push_back(GUGAN(x, y, 1, i, z));
	}
	sort(v.begin(), v.end(), cmp);
	for(auto e : v)
	{
		if(e.type == 1) s.insert(e);
		else
		{
			auto it=s.lower_bound(GUGAN(0, e.e, 0, 0, 0));
			if(it == s.end()) return printf("NO"), 0;
			GUGAN u=*it;
			s.erase(it);
			u.x--;
			dab[e.idx]=u.idx;
			if(u.x != 0) s.insert(u);
		}
	}
	printf("YES\n");
	for(i=0;i<n;i++) printf("%d ", dab[i]+1);
	return 0;
}
//*/


//lxrtxdy!
#include<bits/stdc++.h>
using namespace std;

#define N 100010

int n, a[N], b[N], m, c[N], d[N], f[N];
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
int ans[N];

int main() {
	scanf("%d", &n);
	vector<pii> v, w;
	for (int i = 1; i <= n; i ++) {
		scanf("%d%d", &a[i], &b[i]);
		v.emplace_back(a[i], i);
	}
	scanf("%d", &m);
	for (int i = 1; i <= m; i ++) {
		scanf("%d%d%d", &c[i], &d[i], &f[i]);
		w.emplace_back(c[i], i);
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	v.emplace_back(inf, 0);
	w.emplace_back(inf, 0);
	int now = 0;
	set<int> parts;
	set<pii> actors;
	for (int i = 0, j = 0; i < v.size() && j < w.size();) {
		now = min(v[i].first, w[j].first);
		if (now == inf) break;
		while (w[j].first == now) {
			actors.emplace(d[w[j].second], w[j].second);
			j ++;
		}
		while (v[i].first == now) {
			int j = v[i].second;
			if (!actors.empty()) {
				auto it = actors.lower_bound(pii(b[j],0));
				if (it != actors.end()) {
					int k = it -> second;
					ans[j] = k;
					f[k] --;
					if (!f[k]) actors.erase(it);
				}
			}
			i ++;
		}
	}
	for (int i = 1; i <= n; i ++) {
		if (!ans[i]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	for (int i = 1; i <= n; i ++) printf("%d ", ans[i]);
	return 0;
}

                                                                                //hellobig_tq
//orzlxr!


#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

struct event
{
	int type, x, y, idx;
	event() { type = x = y = 0; }
	event(int _t, int _x, int _y, int i = -1) { type = _t, x = _x, y = _y, idx = i; }
};

int n, m;
vector<event> ev;
int k[MAXN];

void read()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		ev.push_back(event(1, b, a, i));
	}

	cin >> m;
	for(int i = 1; i <= m; i++)
	{
		int a, b;
		cin >> a >> b >> k[i];
		ev.push_back(event(2, b, a, i));
	}
}

int answer[MAXN];

bool cmp(const event &x, const event &y)
{
	if(x.x != y.x) return x.x < y.x;
	return x.type < y.type;
}

set<pair<int, int> > st;

void solve()
{
	sort(ev.begin(), ev.end(), cmp);

	for(auto e: ev)
	{
		if(e.type == 1)
			st.insert({e.y, e.idx});
		else
		{
			int i = e.idx;
			while(k[i])
			{
				auto it = st.lower_bound(make_pair(e.y, -1));
				if(it == st.end()) break;

				k[i]--;
				answer[it->second] = i;
				st.erase(it);
			}
		}
	}

	if(!st.empty())
	{
		cout << "NO" << endl;
		return;
	}

	cout << "YES" << endl;
	for(int i = 1; i <= n; i++) cout << answer[i] << " ";
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    int a, b, c, d, k;
    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a, &b);
        all.push_back(Node{1, a, b, i});
    }

    cin >> m;
    VI can(m);
    for (int i = 0; i < m; ++i) {
        scanf("%d %d %d", &c, &d, &k);
        all.push_back(Node{0, c, d, i});
        can[i] = k;
    }

    sort(all.begin(), all.end(), NodeComparator());

    VI res(n);
    set<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
        }
        else {
            auto it = actor.lower_bound(all[i]);
            if (it == actor.end()) {
                res.clear();
                break;
            }
            res[all[i].id] = it->id;
            --can[it->id];
            if (can[it->id] <= 0) actor.erase(it);
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        cout << "YES" << endl;
        for (auto e : res) cout << (e+1) << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, (i+1)});
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
    }

    sort(all.begin(), all.end(), NodeComparator());

    vector<pair<int, int>> res;
    set<Node> actor;
    map<int, int> cnt;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
            cnt[all[i].id] = all[i].k;
        }
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res.push_back(make_pair(all[i].id, it->id));
            if (cnt[it->id] == 1) actor.erase(it);
            else --cnt[it->id];
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        sort(res.begin(), res.end());
        cout << "YES" << endl;
        for (auto e : res) cout << e.second << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, (i+1)});
    }

    cin >> m;
    VI can(m+1);
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
        can[i+1] = k;
    }

    sort(all.begin(), all.end(), NodeComparator());

    vector<pair<int, int>> res;
    set<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
        }
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res.push_back(make_pair(all[i].id, it->id));
            if (can[it->id] == 1) actor.erase(it);
            else --can[it->id];
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        sort(res.begin(), res.end());
        cout << "YES" << endl;
        for (auto e : res) cout << e.second << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, (i+1)});
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
    }

    sort(all.begin(), all.end(), NodeComparator());

    vector<pair<int, int>> res;
    set<Node> actor;
    map<int, int> can;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            //cout << "actor" << endl;
            actor.insert(all[i]);
            can[all[i].id] = all[i].k;
            //cout << "added" << endl;
            //cout << actor.size() << endl;
        }
        else {
            //cout << "part" << endl;
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) {
                //cout << all[i].x << " " << all[i].y << endl;
                //cout << actor.begin()->x << " " << actor.begin()->y << " " << actor.begin()->id << endl;
                //cout << "no actor" << endl;
                break;
            }
            res.push_back(make_pair(all[i].id, it->id));
            if (can[it->id] == 1) {
                actor.erase(it);
                //cout << "erased" << endl;
                //cout << actor.size() << endl;
            }
            else {
                //cout << "used" << endl;
                --can[it->id];
            }
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        sort(res.begin(), res.end());
        cout << "YES" << endl;
        for (auto e : res) cout << e.second << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b)
    {
        return (y < b.y);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, -1});
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
    }

    sort(all.begin(), all.end(), NodeComparator());

    VI res;
    vector<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0)
            actor.push_back(all[i]);
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res.push_back(it->id);
            if (it->k == 1) actor.erase(it);
            else --(it->k);
        }
        sort(actor.begin(), actor.end());
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        cout << "YES" << endl;
        for (auto e : res) cout << e << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b)
    {
        return (y < b.y);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, (i+1)});
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
    }

    sort(all.begin(), all.end(), NodeComparator());

    vector<pair<int, int>> res;
    vector<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0)
            actor.push_back(all[i]);
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res.push_back(make_pair(all[i].id, it->id));
            if (it->k == 1) actor.erase(it);
            else --(it->k);
        }
        sort(actor.begin(), actor.end());
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        sort(res.begin(), res.end());
        cout << "YES" << endl;
        for (auto e : res) cout << e.second << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, k, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        all.push_back(Node{1, a, b, -1, (i+1)});
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int c, d, k;
        cin >> c >> d >> k;
        all.push_back(Node{0, c, d, k, (i+1)});
    }

    sort(all.begin(), all.end(), NodeComparator());

    vector<pair<int, int>> res(n);
    int cnt = 0;
    set<Node> actor;
    map<int, int> can;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
            can[all[i].id] = all[i].k;
        }
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res[cnt++] = make_pair(all[i].id, it->id);
            if (can[it->id] == 1) actor.erase(it);
            else --can[it->id];
        }
    }

    if (cnt != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        sort(res.begin(), res.end());
        cout << "YES" << endl;
        for (auto e : res) cout << e.second << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    int a, b, c, d, k;
    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a, &b);
        all.push_back(Node{1, a, b, i});
    }

    cin >> m;
    VI can(m);
    for (int i = 0; i < m; ++i) {
        scanf("%d %d %d", &c, &d, &k);
        all.push_back(Node{0, c, d, i});
        can[i] = k;
    }

    sort(all.begin(), all.end(), NodeComparator());

    VI res(n);
    set<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
        }
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) break;
            res[all[i].id] = it->id;
            if (can[it->id] == 1) actor.erase(it);
            else --can[it->id];
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        cout << "YES" << endl;
        for (auto e : res) cout << (e+1) << " "; cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef long long LL;

struct Node {
    int type, x, y, id;
    bool operator<(const Node& b) const
    {
        return (y < b.y) ||
            (y == b.y && type > b.type) ||
            (y == b.y && type == b.type && id < b.id);
    }
};
struct NodeComparator {
    bool operator()(const Node& a, const Node& b)
    {
        return (a.x < b.x) ||
            (a.x == b.x && a.type < b.type) ||
            (a.x == b.x && a.type == b.type && a.y < b.y);
    }
};
int main()
{
    int n, m;
    cin >> n;

    int a, b, c, d, k;
    vector<Node> all;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a, &b);
        all.push_back(Node{1, a, b, i});
    }

    cin >> m;
    VI can(m);
    for (int i = 0; i < m; ++i) {
        scanf("%d %d %d", &c, &d, &k);
        all.push_back(Node{0, c, d, i});
        can[i] = k;
    }

    sort(all.begin(), all.end(), NodeComparator());

    VI res(n);
    set<Node> actor;
    for (int i = 0; i < all.size(); ++i) {
        if (all[i].type == 0) {
            actor.insert(all[i]);
        }
        else {
            auto it = lower_bound(actor.begin(), actor.end(), all[i]);
            if (it == actor.end()) {
                res.clear();
                break;
            }
            res[all[i].id] = it->id;
            --can[it->id];
            if (can[it->id] <= 0) actor.erase(it);
        }
    }

    if (res.size() != n) {
        cout << "NO" << endl;
        return 0;
    }
    else {
        cout << "YES" << endl;
        for (auto e : res) cout << (e+1) << " "; cout << endl;
    }
    return 0;
}


/*
ID: m.nasir1
LANG: C++11
TASK:
*/

#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)(x).size())
#define deb(x) cout << #x << " : " << x << endl
#define debs(x ,y) cout << #x << " : " << x << " , " << #y << " : " << y << endl
#define debind(x , y) cout << #x << "[" << (y) << "] : " << (x)[(y)] << endl
#define pB push_back
#define mP make_pair

#define rep(i , n) for(int (i) = 0 ; (i) < (n) ; ++(i))
#define repinc(i , n) for(int (i) = 1 ; (i) <= (n) ; ++(i))
#define per(i , n) for(int (i) = (n) - 1 ; (i) >= 0 ; --(i))
#define perinc(i , n) for(int (i) = (n) ; (i) >= 1 ; --(i))

typedef long long ll ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
typedef vector < pair < int , int > > vpii ;

#define X first
#define Y second

template <typename T>
ostream & operator <<(ostream & out , const vector < T >& v){
	int ss = sz(v);
	rep(i , ss)
		out << v[i] << " ";
	return out ;
}
template <typename T , typename TT >
ostream & operator <<(ostream & out , const pair < T , TT >& p){
	out << p.first << " " << p.second ;
	return out ;
}
template<typename T , typename TT >
istream & operator >> (istream & in , pair < T , TT >& s){
   in >> s.first >> s.second ;
   return in ;
}
template<typename T>
bitset<sizeof(T)*8> BIN(T a){
	return bitset<sizeof(T)*8>(a);
}

typedef pair < pii , pii > obj ;
typedef obj play;
typedef obj actor ;

#define FR first.first
#define TO first.second
#define TY second.first
#define ID second.second

int n , m ;

obj arr[300002];

int result[200001];

int getType(const obj & a){
	return a.TY != -1 ;
}

bool sorter(const obj & a , const obj & b){
	if(a.FR != b.FR)
		return a.FR  < b.FR;
	if(getType(a) != getType(b)){
		return b.TY < a.TY ;
	}
	return a.TO < b.TO ;
}

struct functor{
	bool operator()(const actor & a , const actor & b)const{
		if(a.TO != b.TO)
			return a.TO < b.TO ;
		else if(getType(a) != getType(b)){
			return a.TY < b.TY ;
		}
		if(a.FR != b.FR)
			return a.FR < b.FR;
		return a.ID < b.ID ;
	}
};

int isGood(const play & pla, const actor & act){
	return (pla.FR >= act.FR) &&( pla.TO <= act.TO) && act.TY;
}

void dis(const obj & a){
	cout << a.FR << " -> "<< a.TO << " : " << a.TY << endl ;
}

int main(){
	cin >> n ;
	int now = 0 ;
	for(int i = 0; i < n ; i++){
		int from , to ;
		cin >> from >> to ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = -1 ;
		arr[now].ID =i ;
		now ++ ;
	}
	cin >> m ;
	for(int i = 0 ; i < m ; i++){
		int from , to , num ;
		cin >> from >> to >> num ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = num ;
		arr[now].ID = i +1;
		now ++ ;
	}

	sort(arr , arr + n + m , sorter);
	set < obj  , functor > st;
	int f=  1 ;
	for(int i = 0 ; i < n + m ; i++){
		if(getType(arr[i])){
			st.insert(arr[i]);
		}
		else{
			auto it = st.lower_bound(arr[i]);
			if(it == st.end()){
				f = 0 ;
				break ;
			}
			actor top = *it ;
			st.erase(it);
			top.TY -- ;
			if(top.TY)
				st.insert(top);
			result[arr[i].ID] = top.ID ;
			}
	}
	if(f){
		cout << "YES" << endl ;
		for(int i = 0 ; i < n ; i++){
			cout << result[i] << " ";
		}
	}
	else
		cout << "NO" << endl ;
	return 0 ;
}


/*
ID: m.nasir1
LANG: C++11
TASK:
*/

#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)(x).size())
#define deb(x) cout << #x << " : " << x << endl
#define debs(x ,y) cout << #x << " : " << x << " , " << #y << " : " << y << endl
#define debind(x , y) cout << #x << "[" << (y) << "] : " << (x)[(y)] << endl
#define pB push_back
#define mP make_pair

#define rep(i , n) for(int (i) = 0 ; (i) < (n) ; ++(i))
#define repinc(i , n) for(int (i) = 1 ; (i) <= (n) ; ++(i))
#define per(i , n) for(int (i) = (n) - 1 ; (i) >= 0 ; --(i))
#define perinc(i , n) for(int (i) = (n) ; (i) >= 1 ; --(i))

typedef long long ll ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
typedef vector < pair < int , int > > vpii ;

#define X first
#define Y second

template <typename T>
ostream & operator <<(ostream & out , const vector < T >& v){
	int ss = sz(v);
	rep(i , ss)
		out << v[i] << " ";
	return out ;
}
template <typename T , typename TT >
ostream & operator <<(ostream & out , const pair < T , TT >& p){
	out << p.first << " " << p.second ;
	return out ;
}
template<typename T , typename TT >
istream & operator >> (istream & in , pair < T , TT >& s){
   in >> s.first >> s.second ;
   return in ;
}
template<typename T>
bitset<sizeof(T)*8> BIN(T a){
	return bitset<sizeof(T)*8>(a);
}

typedef pair < pii , pii > obj ;
typedef obj play;
typedef obj actor ;

#define FR first.first
#define TO first.second
#define TY second.first
#define ID second.second

int n , m ;

obj arr[300002];

int result[200001];

int getType(const obj & a){
	return a.TY != -1 ;
}

bool sorter(const obj & a , const obj & b){
	if(a.FR != b.FR)
		return a.FR  < b.FR;
	if(getType(a) != getType(b)){
		return b.TY < a.TY ;
	}
	return a.TO < b.TO ;
}

struct functor{
	bool operator()(const actor & a , const actor & b)const{
		return b.TO < a.TO ;
	}
};

int isGood(const play & pla, const actor & act){
	return pla.FR >= act.FR && pla.TO <= act.TO && act.TY;
}

int main(){
	cin >> n ;
	int now = 0 ;
	for(int i = 0; i < n ; i++){
		int from , to ;
		cin >> from >> to ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = -1 ;
		arr[now].ID =i ;
		now ++ ;
	}
	cin >> m ;
	for(int i = 0 ; i < m ; i++){
		int from , to , num ;
		cin >> from >> to >> num ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = num ;
		arr[now].ID = i +1;
		now ++ ;
	}

	sort(arr , arr + n + m , sorter);
	priority_queue < obj , vector < obj > , functor > pq ;
	int f=  1 ;
	for(int i = 0 ; i < n + m ; i++){
		if(getType(arr[i])){
			pq.push(arr[i]);
		}
		else{
			while(!pq.empty() && !isGood(arr[i] , pq.top()))
				pq.pop() ;
			if(pq.empty()){
				f = 0 ;
				break ;
			}
			actor top = pq.top() ; pq.pop() ;
			top.TY -- ;
			result[arr[i].ID] = top.ID ;
			pq.push(top);
		}
	}
	if(f){
		cout << "YES" << endl ;
		for(int i = 0 ; i < n ; i++){
			cout << result[i] << " ";
		}
	}
	else
		cout << "NO" << endl ;
	return 0 ;
}


/*
ID: m.nasir1
LANG: C++11
TASK:
*/

#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)(x).size())
#define deb(x) cout << #x << " : " << x << endl
#define debs(x ,y) cout << #x << " : " << x << " , " << #y << " : " << y << endl
#define debind(x , y) cout << #x << "[" << (y) << "] : " << (x)[(y)] << endl
#define pB push_back
#define mP make_pair

#define rep(i , n) for(int (i) = 0 ; (i) < (n) ; ++(i))
#define repinc(i , n) for(int (i) = 1 ; (i) <= (n) ; ++(i))
#define per(i , n) for(int (i) = (n) - 1 ; (i) >= 0 ; --(i))
#define perinc(i , n) for(int (i) = (n) ; (i) >= 1 ; --(i))

typedef long long ll ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
typedef vector < pair < int , int > > vpii ;

#define X first
#define Y second

template <typename T>
ostream & operator <<(ostream & out , const vector < T >& v){
	int ss = sz(v);
	rep(i , ss)
		out << v[i] << " ";
	return out ;
}
template <typename T , typename TT >
ostream & operator <<(ostream & out , const pair < T , TT >& p){
	out << p.first << " " << p.second ;
	return out ;
}
template<typename T , typename TT >
istream & operator >> (istream & in , pair < T , TT >& s){
   in >> s.first >> s.second ;
   return in ;
}
template<typename T>
bitset<sizeof(T)*8> BIN(T a){
	return bitset<sizeof(T)*8>(a);
}

typedef pair < pii , pii > obj ;
typedef obj play;
typedef obj actor ;

#define FR first.first
#define TO first.second
#define TY second.first
#define ID second.second

int n , m ;

obj arr[300002];

int result[200001];

int getType(const obj & a){
	return a.TY != -1 ;
}

bool sorter(const obj & a , const obj & b){
	if(a.FR != b.FR)
		return a.FR  < b.FR;
	if(getType(a) != getType(b)){
		return b.TY < a.TY ;
	}
	return a.TO < b.TO ;
}

struct functor{
	bool operator()(const actor & a , const actor & b)const{
		return a.TO < b.TO ;
	}
};

int isGood(const play & pla, const actor & act){
	return (pla.FR >= act.FR) &&( pla.TO <= act.TO) && act.TY;
}

void dis(const obj & a){
	cout << a.FR << " -> "<< a.TO << " : " << a.TY << endl ;
}

int main(){
	cin >> n ;
	int now = 0 ;
	for(int i = 0; i < n ; i++){
		int from , to ;
		cin >> from >> to ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = -1 ;
		arr[now].ID =i ;
		now ++ ;
	}
	cin >> m ;
	for(int i = 0 ; i < m ; i++){
		int from , to , num ;
		cin >> from >> to >> num ;
		arr[now].FR = from ;
		arr[now].TO = to ;
		arr[now].TY = num ;
		arr[now].ID = i +1;
		now ++ ;
	}

	sort(arr , arr + n + m , sorter);
	set < obj  , functor > st;
	int f=  1 ;
	for(int i = 0 ; i < n + m ; i++){
		if(getType(arr[i])){
			st.insert(arr[i]);
		}
		else{
			auto it = st.lower_bound(arr[i]);
			if(it == st.end()){
				f = 0 ;
				break ;
			}
			actor top = *it ;
			st.erase(it);
			top.TY -- ;
			if(top.TY)
				st.insert(top);
			result[arr[i].ID] = top.ID ;
		}
	}
	if(f){
		cout << "YES" << endl ;
		for(int i = 0 ; i < n ; i++){
			cout << result[i] << " ";
		}
	}
	else
		cout << "NO" << endl ;
	return 0 ;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pi;

struct seg{int s, e, x, y;};

int n, m;
seg a[100005];
seg b[100005];

bool cmpa(seg a, seg b){
    if(a.s != b.s) return a.s < b.s;
    return a.e > b.e;
}

multimap<int,pi> mp;

int match[100005];
int main(){
    memset(match,-1,sizeof(match));
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a[i].s,&a[i].e);
        a[i].x = i;
    }
    sort(a,a+n,cmpa);
    scanf("%d",&m);
    for (int i=0; i<m; i++) {
        scanf("%d %d %d",&b[i].s,&b[i].e,&b[i].y);
        b[i].x = i+1;
    }
    sort(b,b+m,cmpa);
    int st = 0;
    for (int i=0; i<n; i++) {
        while (st < m && b[st].s <= a[i].s) {
            mp.insert(make_pair(b[st].e,pi(b[st].x,b[st].y)));
            // insert!
            st++;
        }
        auto t = mp.lower_bound(a[i].e);
        if(t == mp.end()){
            puts("NO");
            return 0;
        }
        match[a[i].x] = t->second.first;
        t->second.second--;
        if(t->second.second == 0){
            mp.erase(t);
        }
    }
    puts("YES");
    for (int i=0; i<n; i++) {
        printf("%d ",match[i]);
    }
}


#include <set>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX = 100010;

int n, m, lim[MAX], wyn[MAX];
pair < pair <int, int>, int> t[MAX];
pair < pair <int, int>, int> a[MAX];
set < pair <int, int> > s;

int main() {

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d %d", &t[i].first.first, &t[i].first.second);
        t[i].second = i;
    }

    sort(t, t + n);

    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &a[i].first.first, &a[i].first.second, &lim[i]);
        a[i].second = i;
    }

    sort(a, a + m);

    for (int i = 0, j = 0; i < n || j < m;) {
        if (j == m || (i != n && t[i].first.first < a[j].first.first)) {
            auto x = s.lower_bound({t[i].first.second, -1});
            if (x == s.end()) {
                puts("NO");
                exit(0);
            }
            wyn[t[i].second] = x->second + 1;
            lim[x->second]--;
            if (lim[x->second] == 0) {
                s.erase(x);
            }
            i++;
        } else {
            s.insert({a[j].first.second, a[j].second});
            j++;
        }
    }

    printf("YES\n%d", wyn[0]);

    for (int i = 1; i < n; i++) {
        printf(" %d", wyn[i]);
    }

    puts("");

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

vector<iii> V;
vector<iii> actors;
set<ii> S;
int counter[100010];
int matching[100010];

int main() {
   int n, a, b, m, c, d, aidx = 0;
   bool flag = 1;
   scanf("%d", &n);
   for (int i = 0; i < n; i++)
      scanf("%d %d", &a, &b), V.push_back(iii(ii(a, b), i));
   sort(V.begin(), V.end());
   scanf("%d", &m);
   for (int i = 0; i < m; i++) {
      scanf("%d %d %d", &c, &d, &counter[i]);
      actors.push_back(iii(ii(c, d), i));
   }//for
   sort(actors.begin(), actors.end());
   for (int i = 0; i < n; i++) {
      while (aidx != m && actors[aidx].first.first <= V[i].first.first)
         S.insert(ii(actors[aidx].first.second, actors[aidx].second)), aidx++;
      auto it = S.lower_bound(ii(V[i].first.second, 0));
      if (it == S.end()) {
         flag = 0;
         break;
      }//if
      if (--counter[it->second] == 0)
         S.erase(it);
      matching[V[i].second] = it->second;
   }//for
   if (!flag)
      puts("NO");
   else {
      puts("YES");
      for (int i = 0; i < n; i++)
         printf("%d ", matching[i] + 1);
      puts("");
   }//else
   return 0;
}//main


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

vector<iii> V;
vector<iii> actors;
set<ii> S;
int counter[100010];
int matching[100010];

int main() {
   int n, a, b, m, c, d, aidx = 0;
   bool flag = 1;
   scanf("%d", &n);
   for (int i = 0; i < n; i++)
      scanf("%d %d", &a, &b), V.push_back(iii(ii(a, b), i));
   sort(V.begin(), V.end());
   scanf("%d", &m);
   for (int i = 0; i < m; i++) {
      scanf("%d %d %d", &c, &d, &counter[i]);
      actors.push_back(iii(ii(c, d), i));
   }//for
   sort(actors.begin(), actors.end());
   for (int i = 0; i < n; i++) {
      while (aidx != m && actors[aidx].first.first <= V[i].first.first)
         S.insert(ii(actors[aidx].first.second, actors[aidx].second)), aidx++;
      auto it = S.lower_bound(ii(V[i].first.second, 0));
      if (it == S.end()) {
         flag = 0;
         break;
      }//if
      matching[V[i].second] = it->second;
      if (--counter[it->second] == 0)
         S.erase(it);
   }//for
   if (!flag)
      puts("NO");
   else {
      puts("YES");
      for (int i = 0; i < n; i++)
         printf("%d ", matching[i] + 1);
      puts("");
   }//else
   return 0;
}//main


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

vector<ii> V;
vector<iii> actors;
set<ii> S;
int counter[100010];
int matching[100010];

int main() {
   int n, a, b, m, c, d, aidx = 0;
   bool flag = 1;
   scanf("%d", &n);
   for (int i = 0; i < n; i++)
      scanf("%d %d", &a, &b), V.push_back(ii(a, b));
   sort(V.begin(), V.end());
   scanf("%d", &m);
   for (int i = 0; i < m; i++) {
      scanf("%d %d %d", &c, &d, &counter[i]);
      actors.push_back(iii(ii(c, d), i));
   }//for
   sort(actors.begin(), actors.end());
   for (int i = 0; i < n; i++) {
      while (aidx != m && actors[aidx].first.first <= V[i].first)
         S.insert(ii(actors[aidx].first.second, actors[aidx].second)), aidx++;
      auto it = S.lower_bound(ii(V[i].second, 0));
      if (it == S.end()) {
         flag = 0;
         break;
      }//if
      if (--counter[it->second] == 0)
         S.erase(it);
      matching[i] = it->second;
   }//for
   if (!flag)
      puts("NO");
   else {
      puts("YES");
      for (int i = 0; i < n; i++)
         printf("%d ", matching[i] + 1);
      puts("");
   }//else
   return 0;
}//main


#include<bits/stdc++.h>
using namespace std;

#define N 100010

int n, a[N], b[N], m, c[N], d[N], f[N];
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
int ans[N];

int main() {
	scanf("%d", &n);
	vector<pii> v, w;
	for (int i = 1; i <= n; i ++) {
		scanf("%d%d", &a[i], &b[i]);
		v.emplace_back(a[i], i);
	}
	scanf("%d", &m);
	for (int i = 1; i <= m; i ++) {
		scanf("%d%d%d", &c[i], &d[i], &f[i]);
		w.emplace_back(c[i], i);
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	v.emplace_back(inf, 0);
	w.emplace_back(inf, 0);
	int now = 0;
	set<int> parts;
	set<pii> actors;
	for (int i = 0, j = 0; i < v.size() && j < w.size();) {
		now = min(v[i].first, w[j].first);
		if (now == inf) break;
		while (w[j].first == now) {
			actors.emplace(d[w[j].second], w[j].second);
			j ++;
		}
		while (v[i].first == now) {
			int j = v[i].second;
			if (!actors.empty()) {
				auto it = actors.lower_bound(pii(b[j],0));
				if (it != actors.end()) {
					int k = it -> second;
					ans[j] = k;
					f[k] --;
					if (!f[k]) actors.erase(it);
				}
			}
			i ++;
		}
	}
	for (int i = 1; i <= n; i ++) {
		if (!ans[i]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	for (int i = 1; i <= n; i ++) printf("%d ", ans[i]);
	return 0;
}

                                                                                //hellobig_tq


#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

typedef pair<int,int> pii;

const int MX = 100005;

map<int, vector<pii> > remain;
pii song[MX], actor[MX];
pii *S[MX], *A[MX];
int times[MX], answer[MX];

bool comp(const pii* l, const pii *r)
{
    return *l < *r;
}

int main()
{
    int N, M;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) scanf("%d%d", &song[i].first, &song[i].second), S[i] = song+i;
    scanf("%d", &M);
    for(int i = 1; i <= M; i++) scanf("%d%d%d", &actor[i].first, &actor[i].second, times+i), A[i] = actor+i;
    sort(S+1, S+N+1, comp);
    sort(A+1, A+M+1, comp);
    int l = 1;
    bool ch = true;
    for(int i = 1; i <= N; i++){
        pii nw = *S[i];
        while(l <= M && A[l]->first <= nw.first ){
            remain[A[l]->second].push_back(pii(times[A[l] - actor], A[l] - actor) );
            l++;
        }
        auto it = remain.lower_bound(nw.second);
        if( it->second.empty() ) ch = false;
        else{
            answer[S[i] - song] = it->second.back().second;
            it->second.back().first--;
            if( it->second.back().first == 0 ) it->second.pop_back();
            if( it->second.empty() ) remain.erase(it);
        }
    }
    if( !ch ) return !printf("NO\n");
    printf("YES\n");
    for(int i = 1; i <= N; i++) printf("%d ", answer[i]);
}


//Future && You
//              __wyxoi
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 1e5+10;
const int inf = 2e9;
using namespace std;
int read(){
	int x = 0,f = 1,c = getchar();
	while (c<'0' || c>'9') {if (c=='-') f = -1;c = getchar();}
	while (c>='0' && c<='9') x = x*10+c-'0',c = getchar();
	return x*f;
}
int ans[N],n,m,f,nx,num[N];
struct data{int l,r,id;} a[N],b[N];
set <pair<int,int>> S;
bool cmp(data a,data b) {return a.l<b.l || (a.l==b.l && a.r<b.r);}
int main(){
	n = read();
	for (int i=1;i<=n;i++) {a[i].l = read();a[i].r = read();a[i].id = i;}
	m = read();
	for (int i=1;i<=m;i++) {b[i].l = read();b[i].r = read();num[i] = read();b[i].id = i;}
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	nx = f = 1;
	S.insert(make_pair(inf,0));
	for (int i=1;i<=n;i++) {
		for (;nx<=m && b[nx].l<=a[i].l;nx++) S.insert(make_pair(b[nx].r,b[nx].id));
		pair<int,int> tmp = *(S.lower_bound(make_pair(a[i].r,0)));
		if (tmp.first==inf) {f = 0;break;}
		ans[a[i].id] = tmp.second;
		num[tmp.second]--;
		if (num[tmp.second]==0) S.erase(tmp);
	}
	if (!f) return printf("NO"),0;
	else {
		printf("YES\n");
		for (int i=1;i<=n;i++) printf("%d ",ans[i]);
	}
}


//Future && You
//              __wyxoi
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 1e5+10;
const int inf = 2e9;
using namespace std;
int read(){
	int x = 0,f = 1,c = getchar();
	while (c<'0' || c>'9') {if (c=='-') f = -1;c = getchar();}
	while (c>='0' && c<='9') x = x*10+c-'0',c = getchar();
	return x*f;
}
int ans[N],n,m,f,nx;
struct data{int l,r,num,id;} a[N],b[N];
set <pair<int,int>> S;
bool cmp(data a,data b) {return a.l<b.l || (a.l==b.l && a.r<b.r);}
int main(){
	n = read();
	for (int i=1;i<=n;i++) {a[i].l = read();a[i].r = read();a[i].id = i;}
	m = read();
	for (int i=1;i<=m;i++) {b[i].l = read();b[i].r = read();b[i].num = read();b[i].id = i;}
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+m,cmp);
	nx = f = 1;
	S.insert(make_pair(inf,0));
	for (int i=1;i<=n;i++) {
		for (;nx<=m && b[nx].l<=a[i].l;nx++) S.insert(make_pair(b[nx].r,b[nx].id));
		pair<int,int> tmp = *(S.lower_bound(make_pair(a[i].r,0)));
		if (tmp.first==inf) {f = 0;break;}
		ans[a[i].id] = tmp.second;
		b[tmp.second].num--;
		if (b[tmp.second].num==0) S.erase(tmp);
	}
	if (!f) return printf("NO"),0;
	else {
		printf("YES\n");
		for (int i=1;i<=n;i++) printf("%d ",ans[i]);
	}
}


//
//	ID: y0rkl1u
//	PROG: codeforces 497C. Distributing Parts
//	LANG: C++
//	DATE: 03.21.2016
//	NOTE: greedy
//

#include <bits/stdc++.h>
using namespace std;

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif
#define rint register int
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Abs(a) ((a)>=0?(a):(-(a)))
#define cmax(a,b) ((a)<(b)?(a)=(b):1)
#define cmin(a,b) ((a)>(b)?(a)=(b):1)
#define cmod(x) ((x)<0||(x)>=MOD?(x)=((x)%MOD+MOD)%MOD:1)
#define For(i,l,r) for(rint i=(l),_c=(r);i<=_c;i++)
#define Dor(i,l,r) for(rint i=(l),_c=(r);i>=_c;i--)
#define clr(a,sz) memset(a,0,sizeof(a[0])*(sz+5))
#define clrs(a,k,sz) memset(a,k,sizeof(a[0])*(sz+5))
#define pt(x,b) cerr<<#x<<" = "<<x<<(b?'\n':'\t')
#define pa(a,l,r) do{cerr<<#a<<" = ";\
	For(_i,l,r)cerr<<a[_i]<<" \n"[_i==r];}while(0)
#define elif else if
#define ft first
#define sc second
#define MP make_pair
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

struct Sg
{
	int l,r,idx;
	bool operator<(const Sg&t)const{
		return l<t.l||(l==t.l&&idx<t.idx);
	}
};
bool ByR(const Sg&a,const Sg&b)
{
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
const int MN=100010;
int K[MN],Ans[MN],An,Bn;
Sg A[MN],B[MN];
set<Sg> Set;
inline void Main()
{
	scanf("%d",&An);
	For(i,1,An)scanf("%d%d",&A[i].l,&A[i].r),A[i].idx=i;
	sort(A+1,A+1+An,ByR);
	scanf("%d",&Bn);
	For(i,1,Bn)scanf("%d%d%d",&B[i].l,&B[i].r,K+i),B[i].idx=i;
	sort(B+1,B+1+Bn,ByR);
	// greedy assignment
	rint cnt=0,j=1;
	set<Sg>::iterator it;
	For(i,1,Bn){
		for(;j<=An&&A[j].r<=B[i].r;++j)Set.insert(A[j]);
		while(K[B[i].idx]&&!Set.empty()){
			it=Set.lower_bound((Sg){B[i].l,-1,-1});
			if(it==Set.end())break;
			else{
				++cnt,Ans[it->idx]=B[i].idx,--K[B[i].idx];
				Set.erase(it);
			}
		}
// pt(cnt,1);
	}
	if(cnt==An){
		puts("YES");
		For(i,1,An)printf("%d%c",Ans[i]," \n"[i==_c]);
	}
	else puts("NO");
}
int main()
{
	Main();
	return 0;
}


//
//	ID: y0rkl1u
//	PROG: codeforces 497C. Distributing Parts
//	LANG: C++
//	DATE: 03.21.2016
//	NOTE: greedy
//

#include <bits/stdc++.h>
using namespace std;

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif
#define rint register int
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Abs(a) ((a)>=0?(a):(-(a)))
#define cmax(a,b) ((a)<(b)?(a)=(b):1)
#define cmin(a,b) ((a)>(b)?(a)=(b):1)
#define cmod(x) ((x)<0||(x)>=MOD?(x)=((x)%MOD+MOD)%MOD:1)
#define For(i,l,r) for(rint i=(l),_c=(r);i<=_c;i++)
#define Dor(i,l,r) for(rint i=(l),_c=(r);i>=_c;i--)
#define clr(a,sz) memset(a,0,sizeof(a[0])*(sz+5))
#define clrs(a,k,sz) memset(a,k,sizeof(a[0])*(sz+5))
#define pt(x,b) cerr<<#x<<" = "<<x<<(b?'\n':'\t')
#define pa(a,l,r) do{cerr<<#a<<" = ";\
	For(_i,l,r)cerr<<a[_i]<<" \n"[_i==r];}while(0)
#define elif else if
#define ft first
#define sc second
#define MP make_pair
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

struct Sg
{
	int l,r,idx;
	bool operator<(const Sg&t)const{
		return l<t.l||(l==t.l&&idx<t.idx);
	}
};
bool ByR(const Sg&a,const Sg&b)
{
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
const int MN=100010;
int K[MN],Ans[MN],An,Bn;
Sg A[MN],B[MN];
set<Sg> Set;
inline void Main()
{
	scanf("%d",&An);
	For(i,1,An)scanf("%d%d",&A[i].l,&A[i].r),A[i].idx=i;
	sort(A+1,A+1+An,ByR);
	scanf("%d",&Bn);
	For(i,1,Bn)scanf("%d%d%d",&B[i].l,&B[i].r,K+i),B[i].idx=i;
	sort(B+1,B+1+Bn,ByR);
	// greedy assignment
	rint cnt=0,j=1;
	set<Sg>::iterator it;
	For(i,1,Bn){
		for(;j<=Bn&&A[j].r<=B[i].r;++j)Set.insert(A[j]);
		while(K[B[i].idx]&&!Set.empty()){
			it=Set.lower_bound((Sg){B[i].l,-1,-1});
			if(it==Set.end())break;
			else{
				++cnt,Ans[it->idx]=B[i].idx,--K[B[i].idx];
				Set.erase(it);
			}
		}
	}
	if(cnt==An){
		puts("YES");
		For(i,1,An)printf("%d%c",Ans[i]," \n"[i==_c]);
	}
	else puts("NO");
}
int main()
{
	Main();
	return 0;
}


//BISMILLAHIRRAHMANIRRAHIM
/*
 manus tar shopner soman boro
 all my suceesses are dedicated to my parents
 The true test of a man's character is what he does when no one is watching.
 Don't let your dreams be dreams.

 Author :: Shakil Ahmed
.............AUST_CSE27.........
 prob   ::
 Type   ::
 verdict::

*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

// Macro
#define eps 1e-9
#define pi acos(-1.0)
#define ff first
#define ss second
#define re return
#define QI queue<int>
#define SI stack<int>
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sq(a) ((a)*(a))
#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y))
#define iseq(a,b) (fabs(a-b)<eps)
#define eq(a,b) iseq(a,b)
#define ms(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
#define MAX3(a,b,c) max(a,max(b,c))
#define II ( { int a ; read(a) ; a; } )
#define LL ( { Long a ; read(a) ; a; } )
#define DD ({double a; scanf("%lf", &a); a;})

double const EPS=3e-8;
using namespace std;

#define FI freopen ("input.txt", "r", stdin)
#define FO freopen ("output.txt", "w", stdout)

typedef long long Long;
typedef long long int64;
typedef unsigned long long ull;
typedef vector<int> vi ;
typedef set<int> si;
typedef vector<Long>vl;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
typedef pair<Long,Long>pll;
typedef pair<double,double>pdd;
typedef vector<pii> vpii;

// For loop

#define forab(i, a, b)	for (__typeof (b) i = (a) ; i <= b ; ++i)
#define rep(i, n)		forab (i, 0, (n) - 1)
#define For(i, n)		forab (i, 1, n)
#define rofba(i, a, b)	for (__typeof (b)i = (b) ; i >= a ; --i)
#define per(i, n)		rofba (i, 0, (n) - 1)
#define rof(i, n)		rofba (i, 1, n)
#define forstl(i, s)	for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

//Fast Reader
template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

/* **************************************  My code start here ****************************************** */

const int NX = 1e5 + 10 ;

pair < pii , int > a[ NX ] , b[ NX ] ;

int canuse[ NX ] , n , m , ans[ NX ] ;

int main()
{
   // I will always use scanf and printf
   // May be i won't be a good programmer but i will be a good human being

    n = II ;
    rep ( i , n )
    {
        a[i].ff.ff = II ;
        a[i].ff.ss = II ;
        a[i].ss = i ;
    }
    m = II ;
    rep( i , m )
    {
        b[i].ff.ff = II ;
        b[i].ff.ss = II ;
        b[i].ss = i ;
        canuse[ i ] = II ;
    }
    sort( a , a + n );
    sort( b , b + m );
    set < pii > st ;
    int idx = 0 ;
    for ( int i = 0 ; i < n ; i++ )
    {
        while( idx < m && a[i].ff.ff >= b[idx].ff.ff )
        {
            st.insert( mp( b[idx].ff.ss , b[idx].ss ) );
            idx++;
        }
        set < pii > :: iterator it = st.lower_bound(  mp( a[i].ff.ss , 0 ) );
        if( it == st.end() )
        {
            puts("NO");
            return 0 ;
        }
        ans[ a[i].ss ] = it->ss ;
        canuse[ it->ss ]--;
        if( canuse[ it->ss ] == 0 ) st.erase( it );
    }
    puts("YES");
    rep( i , n )
    {
        printf("%d%s",ans[i] + 1, i + 1 == n ? "\n" : " " );
    }

    return 0;
}

// tkirchner@appirio.com


//BISMILLAHIRRAHMANIRRAHIM
/*
 manus tar shopner soman boro
 all my suceesses are dedicated to my parents
 The true test of a man's character is what he does when no one is watching.
 Don't let your dreams be dreams.

 Author :: Shakil Ahmed
.............AUST_CSE27.........
 prob   ::
 Type   ::
 verdict::

*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

// Macro
#define eps 1e-9
#define pi acos(-1.0)
#define ff first
#define ss second
#define re return
#define QI queue<int>
#define SI stack<int>
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sq(a) ((a)*(a))
#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y))
#define iseq(a,b) (fabs(a-b)<eps)
#define eq(a,b) iseq(a,b)
#define ms(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
#define MAX3(a,b,c) max(a,max(b,c))
#define II ( { int a ; read(a) ; a; } )
#define LL ( { Long a ; read(a) ; a; } )
#define DD ({double a; scanf("%lf", &a); a;})

double const EPS=3e-8;
using namespace std;

#define FI freopen ("input.txt", "r", stdin)
#define FO freopen ("output.txt", "w", stdout)

typedef long long Long;
typedef long long int64;
typedef unsigned long long ull;
typedef vector<int> vi ;
typedef set<int> si;
typedef vector<Long>vl;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
typedef pair<Long,Long>pll;
typedef pair<double,double>pdd;
typedef vector<pii> vpii;

// For loop

#define forab(i, a, b)	for (__typeof (b) i = (a) ; i <= b ; ++i)
#define rep(i, n)		forab (i, 0, (n) - 1)
#define For(i, n)		forab (i, 1, n)
#define rofba(i, a, b)	for (__typeof (b)i = (b) ; i >= a ; --i)
#define per(i, n)		rofba (i, 0, (n) - 1)
#define rof(i, n)		rofba (i, 1, n)
#define forstl(i, s)	for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

//Fast Reader
template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

/* **************************************  My code start here ****************************************** */

const int NX = 1e5 + 10 ;

pair < pii , int > a[ NX ] , b[ NX ] ;

int canuse[ NX ] , n , m , ans[ NX ] ;

int main()
{
   // I will always use scanf and printf
   // May be i won't be a good programmer but i will be a good human being

    n = II ;
    rep ( i , n )
    {
        a[i].ff.ff = II ;
        a[i].ff.ss = II ;
        a[i].ss = i ;
    }
    m = II ;
    rep( i , m )
    {
        b[i].ff.ff = II ;
        b[i].ff.ss = II ;
        b[i].ss = i ;
        canuse[ i ] = II ;
    }
    sort( a , a + n );
    sort( b , b + m );
    set < pii > st ;
    int idx = 0 ;
    for ( int i = 0 ; i < n ; i++ )
    {
        while( idx < m && a[i].ff.ff >= b[idx].ff.ff )
        {
            st.insert( mp( b[idx].ff.ss , b[idx].ss ) );
            idx++;
        }
        set < pii > :: iterator it = st.lower_bound(  mp( a[i].ff.ss , 0 ) );
        if( it == st.end() )
        {
            puts("NO");
            return 0 ;
        }
        ans[ i ] = it->ss ;
        canuse[ it->ss ]--;
        if( canuse[ it->ss ] == 0 ) st.erase( it );
    }
    puts("YES");
    rep( i , n )
    {
        printf("%d%s",ans[i] + 1, i + 1 == n ? "\n" : " " );
    }

    return 0;
}

// tkirchner@appirio.com


//BISMILLAHIRRAHMANIRRAHIM
/*
 manus tar shopner soman boro
 all my suceesses are dedicated to my parents
 The true test of a man's character is what he does when no one is watching.
 Don't let your dreams be dreams.

 Author :: Shakil Ahmed
.............AUST_CSE27.........
 prob   ::
 Type   ::
 verdict::

*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

// Macro
#define eps 1e-9
#define pi acos(-1.0)
#define ff first
#define ss second
#define re return
#define QI queue<int>
#define SI stack<int>
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sq(a) ((a)*(a))
#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y))
#define iseq(a,b) (fabs(a-b)<eps)
#define eq(a,b) iseq(a,b)
#define ms(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
#define MAX3(a,b,c) max(a,max(b,c))
#define II ( { int a ; read(a) ; a; } )
#define LL ( { Long a ; read(a) ; a; } )
#define DD ({double a; scanf("%lf", &a); a;})

double const EPS=3e-8;
using namespace std;

#define FI freopen ("input.txt", "r", stdin)
#define FO freopen ("output.txt", "w", stdout)

typedef long long Long;
typedef long long int64;
typedef unsigned long long ull;
typedef vector<int> vi ;
typedef set<int> si;
typedef vector<Long>vl;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
typedef pair<Long,Long>pll;
typedef pair<double,double>pdd;
typedef vector<pii> vpii;

// For loop

#define forab(i, a, b)	for (__typeof (b) i = (a) ; i <= b ; ++i)
#define rep(i, n)		forab (i, 0, (n) - 1)
#define For(i, n)		forab (i, 1, n)
#define rofba(i, a, b)	for (__typeof (b)i = (b) ; i >= a ; --i)
#define per(i, n)		rofba (i, 0, (n) - 1)
#define rof(i, n)		rofba (i, 1, n)
#define forstl(i, s)	for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

//Fast Reader
template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

/* **************************************  My code start here ****************************************** */

const int NX = 1e5 + 10 ;

pair < pii , int > a[ NX ] , b[ NX ] ;

int canuse[ NX ] , n , m , ans[ NX ] ;

int main()
{
   // I will always use scanf and printf
   // May be i won't be a good programmer but i will be a good human being

    n = II ;
    rep ( i , n )
    {
        a[i].ff.ff = II ;
        a[i].ff.ss = II ;
        a[i].ss = i ;
    }
    m = II ;
    rep( i , m )
    {
        b[i].ff.ff = II ;
        b[i].ff.ss = II ;
        b[i].ss = i ;
        canuse[ i ] = II ;
    }
    sort( a , a + n );
    sort( b , b + m );
    set < pii > st ;
    int idx = 0 ;
    for ( int i = 0 ; i < n ; i++ )
    {
        while( idx < m && a[i].ff.ff >= b[idx].ff.ff )
        {
            st.insert( mp( b[idx].ff.ss , b[idx].ss ) );
            idx++;
        }
        set < pii > :: iterator it = st.lower_bound(  mp( a[i].ff.ss , 0 ) );
        if( it == st.end() )
        {
            puts("NO");
            return 0 ;
        }
        ans[ i ] = it->ss ;
        canuse[ it->ss ]--;
        if( canuse[ it->ss ] == 0 ) st.erase( it );
    }
    puts("YES");
    rep( i , n )
    {
        printf("%d%s",ans[i], i + 1 == n ? "\n" : " " );
    }

    return 0;
}

// tkirchner@appirio.com


#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 212345;
int l[N], ans[N], q[N], lx[N];
int main (void) {
	int n; scanf("%d", &n);
	priority_queue < tuple<int, int, int>,
					vector < tuple<int, int, int> >,
					greater < tuple<int, int, int> > > pq;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		lx[i] = a;
		pq.emplace(b, 2, i);
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b, k; cin >> a >> b >> k;
		l[i] = a;
		q[i] = k;
		pq.emplace(b, 3, i);
	}
	set < pii > open;
	memset (ans, -1, sizeof ans);
	while (!pq.empty()) {
		int u, t, id; tie (u, t, id) = pq.top();
		pq.pop();
		if (t == 2) {
			open.insert(mp(lx[id], id));
		} else if (t == 3) {
			while (!open.empty() and q[id]) {
				set<pii>::iterator it;
				it = open.lower_bound(mp(l[id], -1));
				if (it == open.end()) break;
				ans[it->se] = id+1;
				q[id]--;
				open.erase(it);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	for (int i = 0; i < n; i++)
		cout << ans[i] << " \n"[i+1==n];
	return 0;
}


#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 212345;
int l[N], ans[N], q[N], lx[N];
int main (void) {
	int n; scanf("%d", &n);
	priority_queue < tuple<int, int, int>,
					vector < tuple<int, int, int> >,
					greater < tuple<int, int, int> > > pq;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		lx[i] = a;
		pq.emplace(b, 2, i);
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b, k; cin >> a >> b >> k;
		l[i] = a;
		q[i] = k;
		pq.emplace(b, 3, i);
	}
	set < pii > open;
	memset (ans, -1, sizeof ans);
	while (!pq.empty()) {
		int u, t, id; tie (u, t, id) = pq.top();
		pq.pop();
		if (t == 2) {
			open.insert(mp(lx[id], id));
		} else if (t == 3) {
			while (!open.empty() and q[id]) {
				set<pii>::iterator it;
				it = open.lower_bound(mp(u, -1));
				if (it == open.end()) break;
				ans[it->se] = id+1;
				q[id]--;
				open.erase(it);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	for (int i = 0; i < n; i++)
		cout << ans[i] << " \n"[i+1==n];
	return 0;
}


#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 212345;
int l[N], ans[N], q[N], lx[N];
int main (void) {
	int n; scanf("%d", &n);
	priority_queue < tuple<int, int, int>,
					vector < tuple<int, int, int> >,
					greater < tuple<int, int, int> > > pq;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		lx[i] = a;
		pq.emplace(b, 2, i);
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b, k; cin >> a >> b >> k;
		l[i] = a;
		q[i] = k;
		pq.emplace(b, 3, i);
	}
	set < pii > open;
	memset (ans, -1, sizeof ans);
	while (!pq.empty()) {
		int u, t, id; tie (u, t, id) = pq.top();
		pq.pop();
		if (t == 2) {
			open.insert(mp(lx[id], id));
		} else if (t == 3) {
			while (!open.empty() and q[id]) {
				set<pii>::iterator it;
				it = open.upper_bound(mp(u+1, -1));
				if (it == open.begin()) break;
				it--;
				ans[it->se] = id+1;
				q[id]--;
				open.erase(it);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	for (int i = 0; i < n; i++)
		cout << ans[i] << " \n"[i+1==n];
	return 0;
}


#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 212345;
int l[N], ans[N], q[N], lx[N];
int main (void) {
	int n; scanf("%d", &n);
	priority_queue < tuple<int, int, int>,
					vector < tuple<int, int, int> >,
					greater < tuple<int, int, int> > > pq;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		lx[i] = a;
		pq.emplace(b, 2, i);
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b, k; cin >> a >> b >> k;
		l[i] = a;
		q[i] = k;
		pq.emplace(b, 3, i);
	}
	set < pii > open;
	memset (ans, -1, sizeof ans);
	while (!pq.empty()) {
		int u, t, id; tie (u, t, id) = pq.top();
		pq.pop();
		if (t == 2) {
			open.insert(mp(lx[id], id));
		} else if (t == 3) {
			while (!open.empty() and q[id]) {
				set<pii>::iterator it;
				it = open.lower_bound(mp(u, -1));
				if (it == open.begin()) break;
				ans[it->se] = id+1;
				q[id]--;
				open.erase(it);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	for (int i = 0; i < n; i++)
		cout << ans[i] << " \n"[i+1==n];
	return 0;
}


#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 212345;
int l[N], ans[N], q[N], lx[N];
int main (void) {
	int n; scanf("%d", &n);
	priority_queue < tuple<int, int, int>,
					vector < tuple<int, int, int> >,
					greater < tuple<int, int, int> > > pq;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		lx[i] = a;
		pq.emplace(b, 2, i);
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b, k; cin >> a >> b >> k;
		l[i] = a;
		q[i] = k;
		pq.emplace(b, 3, i);
	}
	set < pii > open;
	memset (ans, -1, sizeof ans);
	while (!pq.empty()) {
		int u, t, id; tie (u, t, id) = pq.top();
		pq.pop();
		if (t == 2) {
			open.insert(mp(lx[u], id));
		} else if (t == 3) {
			while (!open.empty() and q[id]) {
				set<pii>::iterator it;
				it = open.upper_bound(mp(u+1, -1));
				if (it == open.begin()) break;
				it--;
				ans[it->se] = id+1;
				q[id]--;
				open.erase(it);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	for (int i = 0; i < n; i++)
		cout << ans[i] << " \n"[i+1==n];
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 6;
struct Event
{
    int add;
    int id;
    int l, r;
    Event(){}
    Event(int _add, int _id, int _l, int _r)
    {
        add = _add;
        id = _id;
        l = _l;
        r = _r;
    }
};

bool operator<(Event x, Event y)
{
    if (x.l != y.l) return x.l > y.l;
    if (x.add != y.add) return x.add > y.add;
    if (x.r != y.r) return x.r < y.r;
    return x.id < y.id;
}
int res[MAXN];
int cnt[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
    vector<Event> e;
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        e.push_back(Event(1, i, a, b));
    }
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d %d %d", &a, &b, &cnt[i]);
        e.push_back(Event(0, i, a, b));
    }
    sort(e.begin(), e.end());
    set<pair<int, int> >go;
    for (int i = 0; i < (int)e.size(); i++)
    {
        if (e[i].add == 1)
        {
        //    cerr << "ADDED: " << e[i].id << endl;
            go.insert(make_pair(e[i].r, e[i].id));
        }
        else
        {
       //     cerr << "SING: " << e[i].id << endl;
            int canTake = cnt[e[i].id];
            while (1)
            {
                if (canTake == 0) break;
                set<pair<int, int> >::iterator it = go.lower_bound(make_pair(e[i].r + 1, -1));
                if (it == go.begin()) break;
                it--;
                res[it->second] = e[i].id;
     //           cerr << "SONG: " << it->second << endl;
                canTake--;
                go.erase((*it));
            }
        }
    }
    bool ok = true;
    for (int i = 1; i <= n; i++)
    {
        if (res[i] == 0)
        {
            ok = false;
        }
    }
    if (!ok)
    {
        puts("NO");
        return 0;
    }
    puts("YES");
    for (int i = 1; i <= n; i++)
    {
        printf("%d ", res[i]);
    }
    printf("\n");
}


#include<iostream>
using namespace std;
int main()
{int n;
cin>>n;
int i,temp,sum=0;
for(i=0;i<n;i++)
{cin>>temp;sum=sum+temp;}
if(sum%4==0)cout<<sum/4;
else cout<<(sum/4)+(sum%4);

return 0;}


#include<iostream>
using namespace std;
int main()
{int n;
cin>>n;
int i,temp,sum=0;
for(i=0;i<n;i++)
{cin>>temp;sum=sum+temp;}
if(sum%4==0)cout<<sum/4;
else cout<<(sum/4)+1;

return 0;}


#include <iostream>
#include<cstdio>
using namespace std;

int main() {
    int n;
cin>>n;
int i,a,sum=0,cars=0,one=0,two=0,three=0,four=0;
for(i=0;i<n;i++)
{scanf("%d",&a);
if(a==1)one++;
if(a==2)two++;
if(a==3)three++;
if(a==4)four++;
}
if(one>three){sum=sum+three;one=one-three;three=0;}
else {sum=sum+one;three=three-one;one=0;}
    sum=sum+two/4;
    sum=sum+one/4;
    if(two%4!=0){sum=sum+1;if(one%4<=2)one=0;else if(one%4>2)one=one-2;}

    if(one%4!=0)sum=sum+1;
    sum=sum+three+four;
    cout<<sum;

    return 0;
}


#include <iostream>
#include<cstdio>
using namespace std;

int main() {
    int n;
cin>>n;
int i,a,sum=0,cars=0,one=0,two=0,three=0,four=0;
for(i=0;i<n;i++)
{scanf("%d",&a);
if(a==1)one++;
if(a==2)two++;
if(a==3)three++;
if(a==4)four++;
}
if(one>three){sum=sum+three;one=one-three;three=0;}
else {sum=sum+one;three=three-one;one=0;}
    sum=sum+two/2;
    sum=sum+one/4;
    if(two%2!=0){sum=sum+1;if(one%4<=2)one=0;else if(one%4>2)one=one-2;}

    if(one%4!=0)sum=sum+1;
    sum=sum+three+four;
    cout<<sum;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{int n;
cin>>n;
int i,a,sum=0,cars=0,one=0,two=0,three=0,four=0;
for(i=0;i<n;i++)
{scanf("%d",&a);
if(a==1)one++;
if(a==2)two++;
if(a==3)three++;
if(a==4)four++;
}

sum+=four;
if(one>three)
{
sum=sum+one-three;
one=one-three;
sum=sum+two/2;
if(two%2!=0){sum=sum+1;}
sum=one-2*two;
one=one-2*two;
sum=sum+one;

}

else {sum=sum+three-one;

one=0;
sum=sum+two/2;
if(two%2!=0){sum=sum+1;}

sum=sum+one;
}
cout<<sum+four<<endl;
return 0;}


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{int n;
cin>>n;
int i,a,sum=0,cars=0,one=0,two=0,three=0,four=0;
for(i=0;i<n;i++)
{scanf("%d",&a);
if(a==1)one++;
if(a==2)two++;
if(a==3)three++;
if(a==4)four++;
}

sum+=four;
if(one>three)
{
sum=sum+three;
one=one-three;
sum=sum+two/2;
if(two%2!=0){sum=sum+1;}
sum=one-2*two;
one=one-2*two;
sum=sum+one;

}

else {sum=sum+one;

sum=sum+three-one;
sum=sum+two/4;
if(two%4!=0){sum=sum+1;}

}
cout<<sum<<endl;
return 0;}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n;
cin>>n;
int i,a[n],sum=0,cars=0,one=0,two=0,three=0,four=0;
for(i=0;i<n;i++)
{cin>>a[i];
if(a[i]==1)one++;
if(a[i]==2)two++;
if(a[i]==3)three++;
if(a[i]==4)four++;
}
if(three==one && two%4==0)
cout<<two/4+three+four;
else if(three>one && two%4==0)
cout<<two/4+three+four;
else if(three<one && two%4==0)
cout<<two/4+three+(three)+(one-three)+four;
else if(three==one && two%4!=0)
cout<<two/4+three+four+1;
else if(three>one && two%4!=0)
cout<<two/4+1+three+four;
else if(three<one && two%4!=0 && (one-three)%4<=2)
cout<<(three)+(two+one-three)/4+four;
else if(three<one && two%4!=0 && (one-three)%4>2)
cout<<three+two/4+1+(one-three)+four;

return 0;}


#include<iostream>

using namespace std;

int main() {
    int n;
    int  count = 0;
    int *arr;
    cin >> n;
    arr = new int[n];
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
        count += arr[i];
    }
    if(count%4 != 0) {
        count = count / 4;
        count++;
    }
    else {
        count = count / 4;
    }

    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int so2 = 0, so3 = 0, so1 = 0;
    int  count = 0;
    int *arr;
    long n;
    cin >> n;
    arr = new int[n];
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
        count += arr[i];
        if(arr[i] == 2) so2++;
        else if(arr[i] == 3) so3++;
        else if(arr[i] == 1) so1++;
    }
    if(count%4 != 0) {
        count = count / 4;
        count++;
    }
    else {
        count = count / 4;
    }
    if(so2 > so1 && so3 > so2) {
        count++;
    }

    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int n, so2 = 0, so3 = 0, so1 = 0;
    int  count = 0;
    int *arr;
    cin >> n;
    arr = new int[n];
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
        count += arr[i];
        if(arr[i] == 2) so2++;
        else if(arr[i] == 3) so3++;
        else if(arr[i] == 1) so1++;
    }
    if(count%4 != 0) {
        count = count / 4;
        count++;
    }
    else {
        count = count / 4;
    }
    if(so2 > so1 && so3 > so2) {
        count++;
    }

    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int arr[5];
    int n, t, count;
    arr[4] = arr[1] = arr[2] = arr[3] = 0;
    cin >> n;
    while(n--) {
        cin >> t;
        arr[t]++;
    }

    count = arr[4] + (arr[2]*2 + 2) / 4 + (arr[3]*3 + arr[1] + (arr[3] > arr[1] ? 4 : 1))/4;
    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int so2 = 0, so3 = 0, so1 = 0, so4 = 0;
    int  count = 0;
    int *arr;
    long int n;
    cin >> n;
    arr = new int[n];
    for(long int i = 0; i < n; ++i) {
        cin >> arr[i];
        count += arr[i];
        if(arr[i] == 2) so2++;
        else if(arr[i] == 3) so3++;
        else if(arr[i] == 1) so1++;
        else if(arr[i] == 4) so4++;
    }
    if(so3 == n || so4 == n) {
        cout << n;
    }
    else {
        if(count%4 != 0) {
        count = count / 4;
        count++;
        }
        else {
            count = count / 4;
        }
        if(so2 > so1 && so3 > so2) {
            count++;
        }

        cout << count;
    }

}


#include<iostream>

using namespace std;

int main() {
    int arr[5];
    int n, t, count;
    arr[4] = arr[1] = arr[2] = arr[3] = 0;
    cin >> n;
    while(n--) {
        cin >> t;
        arr[t]++;
    }

    count = arr[3] + arr[4] + ((((arr[1] - arr[3]) >= 0 ? (arr[1] - arr[3]) : 0) + arr[2]*2 + 3 + arr[1]))/4;
    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int arr[5];
    int n, t, count;
    arr[4] = arr[1] = arr[2] = arr[3] = 0;
    cin >> n;
    while(n--) {
        cin >> t;
        arr[t]++;
    }

    count = arr[3] + arr[4] + ((((arr[1] - arr[3]) >= 0 ? (arr[1] - arr[3]) : 0) + arr[2]*2 + 3))/4;
    cout << count;
}


#include<iostream>

using namespace std;

int main() {
    int so2 = 0, so3 = 0, so1 = 0;
    int  count = 0;
    int *arr;
    long int n;
    cin >> n;
    arr = new int[n];
    for(long int i = 0; i < n; ++i) {
        cin >> arr[i];
        count += arr[i];
        if(arr[i] == 2) so2++;
        else if(arr[i] == 3) so3++;
        else if(arr[i] == 1) so1++;
    }
    if(count%4 != 0) {
        count = count / 4;
        count++;
    }
    else {
        count = count / 4;
    }
    if(so2 > so1 && so3 > so2) {
        count++;
    }

    cout << count;
}


#include <iostream>
#include <vector>
#include <algorithm>

void func(int n, std::vector<int>& dist, int& res, std::vector<int>& pat){
    if(n == 0){
        if(int n = [&pat, &dist]() -> int{
                    int ret = 0;
                    for(int i = 0; i < dist.size(); ++i){
                        if(dist[i] < pat[i]) return 0;
                        if(pat[i])
                            ret = std::max(ret, dist[i] / pat[i]);
                    }
                    return ret;
                }()){
            res += n;
            for(int i = 0; i < dist.size(); ++i)
                dist[i] -= pat[i] * n;
        }
    }else{
        for(int i = n; i > 0; --i){
            ++pat[i - 1];
            func(n - i, dist, res, pat);
            --pat[i - 1];
        }
    }
}

int attack(std::vector<int> dist){
    int res = 0;
    std::vector<int> pat(dist.size(), 0);
    while(!dist.empty()){
        func(dist.size(), dist, res, pat);
        dist.erase(dist.end() - 1, dist.end());
    }
    return res;
}

int main(){
    const int LIM = 4;
    int res = 0;
    int n;
    std::cin >> n;
    std::vector<int> dist(LIM, 0);
    for(int i = 0; i < n; ++i){
        int t;
        std::cin >> t;
        ++dist[t - 1];
    }
    std::cout << attack(dist) << std::endl;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> s(n + 1, 0);

    for(int i = 0; i < n; ++i){
        int tmp;
        std::cin >> tmp;
        ++s[tmp];
    }

    int res = 0;

    res += s[1] / 4;
    s[1] %= 4;

    {
        int tmp = std::min(s[1] / 2, s[2]);
        res += tmp;
        s[1] -= tmp * 2;
        s[2] -= tmp;
    }

    res += s[2] / 2;
    s[2] %= 2;

    {
        int tmp = std::min(s[1], s[3]);
        s[1] -= tmp;
        s[2] -= tmp;
    }

    res += s[1] + s[2] + s[3] + s[4];

    std::cout << res << std::endl;
}


#include <iostream>
#include <vector>
#include <stack>

bool strip(std::vector<int> vec){
    auto i = vec.rbegin();
    while(i != vec.rend() && *i == 0) ++i;
    if(i == vec.rend()) return false;
    vec.erase((--i).base(), vec.end());
    return true;
}

void func(int n, std::vector<int>& dist, int& res, std::vector<int>& pat){
    if(n == 0){
        while([&pat, &dist](){
                    for(int i = 0; i < dist.size(); ++i)
                        if(dist[i] < pat[i]) return false;
                    return true;
                }()){
            ++res;
            for(int i = 0; i < dist.size(); ++i)
                dist[i] -= pat[i];
        }
    }else{
        for(int i = n; i > 0; --i){
            ++pat[i - 1];
            func(n - i, dist, res, pat);
            --pat[i - 1];
        }
    }
}

int attack(std::vector<int> dist){
    int res = 0;
    std::vector<int> pat(dist.size(), 0);
    while(!dist.empty()){
        func(dist.size(), dist, res, pat);
        dist.erase(dist.end() - 1, dist.end());
    }
    for(auto elem : dist) res += elem;
    return res;
}

int main(){
    const int LIM = 4;
    int res = 0;
    int n;
    std::cin >> n;
    std::vector<int> dist(LIM, 0);
    for(int i = 0; i < n; ++i){
        int t;
        std::cin >> t;
        ++dist[t - 1];
    }
    std::cout << attack(dist) << std::endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

void func(int n, std::vector<int>& dist, int& res, std::vector<int>& pat){
    if(n == 0){
        int n = [&pat, &dist]() -> int{
                    int ret = std::numeric_limits<int>::max();
                    for(int i = 0; i < dist.size(); ++i){
                        if(pat[i])
                            ret = std::min(ret, dist[i] / pat[i]);
                    }
                    return ret;
                }();
        res += n;
        for(int i = 0; i < dist.size(); ++i)
            dist[i] -= pat[i] * n;
    }else{
        for(int i = n; i > 0; --i){
            if(!dist[i - 1]) continue;
            ++pat[i - 1];
            func(n - i, dist, res, pat);
            --pat[i - 1];
        }
    }
}

int attack(std::vector<int> dist){
    int res = 0;
    std::vector<int> pat(dist.size(), 0);
    while(!dist.empty()){
        func(dist.size(), dist, res, pat);
        dist.erase(dist.end() - 1, dist.end());
    }
    return res;
}

int main(){
    const int LIM = 4;
    int res = 0;
    int n;
    std::cin >> n;
    std::vector<int> dist(LIM, 0);
    for(int i = 0; i < n; ++i){
        int t;
        std::cin >> t;
        ++dist[t - 1];
    }
    std::cout << attack(dist) << std::endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

void func(int n, std::vector<int>& dist, int& res, std::vector<int>& pat){
    if(n == 0){
        if(int n = [&pat, &dist]() -> int{
                    int ret = std::numeric_limits<int>::max();
                    for(int i = 0; i < dist.size(); ++i){
                        if(dist[i] < pat[i]) return 0;
                        if(pat[i])
                            ret = std::min(ret, dist[i] / pat[i]);
                    }
                    return ret;
                }()){
            res += n;
            for(int i = 0; i < dist.size(); ++i)
                dist[i] -= pat[i] * n;
        }
    }else{
        for(int i = n; i > 0; --i){
            if(!dist[i - 1]) continue;
            ++pat[i - 1];
            func(n - i, dist, res, pat);
            --pat[i - 1];
        }
    }
}

int attack(std::vector<int> dist){
    int res = 0;
    std::vector<int> pat(dist.size(), 0);
    while(!dist.empty()){
        func(dist.size(), dist, res, pat);
        dist.erase(dist.end() - 1, dist.end());
    }
    return res;
}

int main(){
    const int LIM = 4;
    int res = 0;
    int n;
    std::cin >> n;
    std::vector<int> dist(LIM, 0);
    for(int i = 0; i < n; ++i){
        int t;
        std::cin >> t;
        ++dist[t - 1];
    }
    std::cout << attack(dist) << std::endl;
}