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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r;
    int t; // 0 - x   1 - y
    Node *left, *right, *vertical;
    int minv;
    vector<int> *v;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];
vector<int> ux, uy;
int uxn, uyn;
map<int, int> mapx, mapy;

Node *CreateNode(const int &l, const int &r, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->t = t; ret->minv = INT_MAX;
    ret->left = ret->right = ret->vertical = NULL;
    ret->v = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        if(nowp->vertical == NULL) nowp->vertical = CreateNode(0, uyn - 1, 1);
        Add(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            if(nowp->v == NULL) nowp->v = new vector<int>;
            nowp->v->push_back(id);
            nowp->minv = nowp->v->front();
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
    {
        if(nowp->left == NULL) nowp->left = CreateNode(nowp->l, mid, nowp->t);
        Add(nowp->left, x, y, id);
    }
    else
    {
        if(nowp->right == NULL) nowp->right = CreateNode(mid + 1, nowp->r, nowp->t);
        Add(nowp->right, x, y, id);
    }

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(nowp->t == 0 && ux[nowp->l] >= x0 && ux[nowp->r] <= x1)
        return GetMin(nowp->vertical, x0, x1, y0, y1);

    if(nowp->t == 1 && uy[nowp->l] >= y0 && uy[nowp->r] <= y1)
        return nowp->minv;

    int mid = (nowp->l + nowp->r) / 2;
    int minvv = INT_MAX;

    if(nowp->t == 0)
    {
        minvv = min(minvv, GetMin(nowp->left, x0, min(ux[mid], x1), y0, y1));
        minvv = min(minvv, GetMin(nowp->right, max(ux[mid + 1], x0), x1, y0, y1));
    }
    else
    {
        minvv = min(minvv, GetMin(nowp->left, x0, x1, y0, min(uy[mid], y1)));
        minvv = min(minvv, GetMin(nowp->right, x0, x1, max(uy[mid + 1], y0), y1));
    }

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        Del(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            nowp->v->erase(lower_bound(nowp->v->begin(), nowp->v->end(), id));
            if(nowp->v->empty()) nowp->minv = INT_MAX;
            else nowp->minv = nowp->v->front();
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
        Del(nowp->left, x, y, id);
    else
        Del(nowp->right, x, y, id);

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), ux.push_back(sa[i].x), uy.push_back(sa[i].y);
    sort(ux.begin(), ux.end());
    sort(uy.begin(), uy.end());
    ux.erase(unique(ux.begin(), ux.end()), ux.end());
    uy.erase(unique(uy.begin(), uy.end()), uy.end());
    uxn = ux.size(); uyn = uy.size();
    for(int i = 0; i < uxn; i++) mapx[ux[i]] = i;
    for(int i = 0; i < uyn; i++) mapy[uy[i]] = i;
    root = CreateNode(0, uxn - 1, 0);
    for(int i = 0; i < m; i++) Add(root, mapx[sa[i].x], mapy[sa[i].y], i);

    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, mapx[sa[shootid].x], mapy[sa[shootid].y], shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r;
    int t; // 0 - x   1 - y
    Node *left, *right, *vertical;
    int minv;
    queue<int> *q;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];
vector<int> ux, uy;
int uxn, uyn;
map<int, int> mapx, mapy;

Node *CreateNode(const int &l, const int &r, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->t = t; ret->minv = INT_MAX;
    ret->left = ret->right = ret->vertical = NULL;
    ret->q = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        if(nowp->vertical == NULL) nowp->vertical = CreateNode(0, uyn - 1, 1);
        Add(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            if(nowp->q == NULL) nowp->q = new queue<int>;
            nowp->q->push(id);
            nowp->minv = nowp->q->front();
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
    {
        if(nowp->left == NULL) nowp->left = CreateNode(nowp->l, mid, nowp->t);
        Add(nowp->left, x, y, id);
    }
    else
    {
        if(nowp->right == NULL) nowp->right = CreateNode(mid + 1, nowp->r, nowp->t);
        Add(nowp->right, x, y, id);
    }

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(nowp->t == 0 && ux[nowp->l] >= x0 && ux[nowp->r] <= x1)
        return GetMin(nowp->vertical, x0, x1, y0, y1);

    if(nowp->t == 1 && uy[nowp->l] >= y0 && uy[nowp->r] <= y1)
        return nowp->minv;

    int mid = (nowp->l + nowp->r) / 2;
    int minvv = INT_MAX;

    if(nowp->t == 0)
    {
        minvv = min(minvv, GetMin(nowp->left, x0, min(ux[mid], x1), y0, y1));
        minvv = min(minvv, GetMin(nowp->right, max(ux[mid + 1], x0), x1, y0, y1));
    }
    else
    {
        minvv = min(minvv, GetMin(nowp->left, x0, x1, y0, min(uy[mid], y1)));
        minvv = min(minvv, GetMin(nowp->right, x0, x1, max(uy[mid + 1], y0), y1));
    }

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        Del(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            nowp->q->pop();
            if(nowp->q->empty()) nowp->minv = INT_MAX;
            else nowp->minv = nowp->q->front();
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
        Del(nowp->left, x, y, id);
    else
        Del(nowp->right, x, y, id);

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), ux.push_back(sa[i].x), uy.push_back(sa[i].y);
    sort(ux.begin(), ux.end());
    sort(uy.begin(), uy.end());
    ux.erase(unique(ux.begin(), ux.end()), ux.end());
    uy.erase(unique(uy.begin(), uy.end()), uy.end());
    uxn = ux.size(); uyn = uy.size();
    for(int i = 0; i < uxn; i++) mapx[ux[i]] = i;
    for(int i = 0; i < uyn; i++) mapy[uy[i]] = i;
    root = CreateNode(0, uxn - 1, 0);
    for(int i = 0; i < m; i++) Add(root, mapx[sa[i].x], mapy[sa[i].y], i);

    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, mapx[sa[shootid].x], mapy[sa[shootid].y], shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r, b, t;
    Node *child[4];
    int minv;
    queue<int> *q;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];

Node *CreateNode(const int &l, const int &r, const int &b, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->b = b; ret->t = t; ret->minv = INT_MAX;
    ret->child[0] = ret->child[1] = ret->child[2] = ret->child[3] = NULL;
    ret->q = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int subl, subr, subb, subt, areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        if(nowp->q == NULL) nowp->q = new queue<int>;
        nowp->q->push(id);
        nowp->minv = nowp->q->front();
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0, subl = nowp->l, subr = midlr, subb = nowp->b, subt = midbt;
            else areai = 2, subl = nowp->l, subr = midlr, subb = midbt + 1, subt = nowp->t;
        }
        else
        {
            if(y <= midbt) areai = 1, subl = midlr + 1, subr = nowp->r, subb = nowp->b, subt = midbt;
            else areai = 3, subl = midlr + 1, subr = nowp->r, subb = midbt + 1, subt = nowp->t;
        }
        if(nowp->child[areai] == NULL) nowp->child[areai] = CreateNode(subl, subr, subb, subt);
        Add(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(nowp->l == x0 && nowp->r == x1 && nowp->b == y0 && nowp->t == y1) return nowp->minv;

    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int minvv = INT_MAX;

    minvv = min(minvv, GetMin(nowp->child[0], x0, min(midlr, x1), y0, min(midbt, y1)));
    minvv = min(minvv, GetMin(nowp->child[1], max(midlr + 1, x0), x1, y0, min(midbt, y1)));
    minvv = min(minvv, GetMin(nowp->child[2], x0, min(midlr, x1), max(midbt + 1, y0), y1));
    minvv = min(minvv, GetMin(nowp->child[3], max(midlr + 1, x0), x1, max(midbt + 1, y0), y1));

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        nowp->q->pop();
        if(nowp->q->empty()) nowp->minv = INT_MAX;
        else nowp->minv = nowp->q->front();
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0;
            else areai = 2;
        }
        else
        {
            if(y <= midbt) areai = 1;
            else areai = 3;
        }
        Del(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    root = CreateNode(0, MAXRANGE, 0, MAXRANGE);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), Add(root, sa[i].x, sa[i].y, i);
    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, sa[shootid].x, sa[shootid].y, shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
int ansa[MAXN];
int next[MAXN];
int head;

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1, next[i] = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y));
    head = 0;

    for(int i = 0; i < m; i++)
    {
        for(int j = head, pre = head; j != n; pre = j, j = next[j])
        if(ta[j].x0 <= sa[i].x && sa[i].x <= ta[j].x1 && ta[j].y0 <= sa[i].y && sa[i].y <= ta[j].y1)
        {
            ansa[i] = ta[j].id;
            if(j == head) head = next[j];
            else next[pre] = next[j];
            break;
        }
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
int ansa[MAXN];
int next[MAXN];
int head;

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), next[i] = i + 1;
    head = 0;

    for(int i = 0; i < n; i++)
    {
        for(int j = head, pre = head; j != m; pre = j, j = next[j])
        if(ta[i].x0 <= sa[j].x && sa[j].x <= ta[i].x1 && ta[i].y0 <= sa[j].y && sa[j].y <= ta[i].y1)
        {
            ansa[j] = ta[i].id;
            if(j == head) head = next[j];
            else next[pre] = next[j];
            break;
        }
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r, b, t;
    Node *child[4];
    int minv;
    set<int> *s;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];

Node *CreateNode(const int &l, const int &r, const int &b, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->b = b; ret->t = t; ret->minv = INT_MAX;
    ret->child[0] = ret->child[1] = ret->child[2] = ret->child[3] = NULL;
    ret->s = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int subl, subr, subb, subt, areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        if(nowp->s == NULL)
        {
            nowp->s = new set<int>;
            nowp->s->insert(id);
            nowp->minv = id;
        }
        else
            nowp->s->insert(id);
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0, subl = nowp->l, subr = midlr, subb = nowp->b, subt = midbt;
            else areai = 2, subl = nowp->l, subr = midlr, subb = midbt + 1, subt = nowp->t;
        }
        else
        {
            if(y <= midbt) areai = 1, subl = midlr + 1, subr = nowp->r, subb = nowp->b, subt = midbt;
            else areai = 3, subl = midlr + 1, subr = nowp->r, subb = midbt + 1, subt = nowp->t;
        }
        if(nowp->child[areai] == NULL) nowp->child[areai] = CreateNode(subl, subr, subb, subt);
        Add(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(nowp->l == x0 && nowp->r == x1 && nowp->b == y0 && nowp->t == y1) return nowp->minv;

    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int minvv = INT_MAX;

    minvv = min(minvv, GetMin(nowp->child[0], x0, min(midlr, x1), y0, min(midbt, y1)));
    minvv = min(minvv, GetMin(nowp->child[1], max(midlr + 1, x0), x1, y0, min(midbt, y1)));
    minvv = min(minvv, GetMin(nowp->child[2], x0, min(midlr, x1), max(midbt + 1, y0), y1));
    minvv = min(minvv, GetMin(nowp->child[3], max(midlr + 1, x0), x1, max(midbt + 1, y0), y1));

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        nowp->s->erase(id);
        if(nowp->s->empty()) nowp->minv = INT_MAX;
        else nowp->minv = *(nowp->s->begin());
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0;
            else areai = 2;
        }
        else
        {
            if(y <= midbt) areai = 1;
            else areai = 3;
        }
        Del(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    root = CreateNode(0, MAXRANGE, 0, MAXRANGE);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), Add(root, sa[i].x, sa[i].y, i);
    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, sa[shootid].x, sa[shootid].y, shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r;
    int t; // 0 - x   1 - y
    Node *left, *right, *vertical;
    int minv;
    set<int> *s;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];
vector<int> ux, uy;
int uxn, uyn;
map<int, int> mapx, mapy;

Node *CreateNode(const int &l, const int &r, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->t = t; ret->minv = INT_MAX;
    ret->left = ret->right = ret->vertical = NULL;
    ret->s = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        if(nowp->vertical == NULL) nowp->vertical = CreateNode(0, uyn - 1, 1);
        Add(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            if(nowp->s == NULL) nowp->s = new set<int>;
            nowp->s->insert(id);
            nowp->minv = *(nowp->s->begin());
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
    {
        if(nowp->left == NULL) nowp->left = CreateNode(nowp->l, mid, nowp->t);
        Add(nowp->left, x, y, id);
    }
    else
    {
        if(nowp->right == NULL) nowp->right = CreateNode(mid + 1, nowp->r, nowp->t);
        Add(nowp->right, x, y, id);
    }

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(nowp->t == 0 && ux[nowp->l] >= x0 && ux[nowp->r] <= x1)
        return GetMin(nowp->vertical, x0, x1, y0, y1);

    if(nowp->t == 1 && uy[nowp->l] >= y0 && uy[nowp->r] <= y1)
        return nowp->minv;

    int mid = (nowp->l + nowp->r) / 2;
    int minvv = INT_MAX;

    if(nowp->t == 0)
    {
        minvv = min(minvv, GetMin(nowp->left, x0, min(ux[mid], x1), y0, y1));
        minvv = min(minvv, GetMin(nowp->right, max(ux[mid + 1], x0), x1, y0, y1));
    }
    else
    {
        minvv = min(minvv, GetMin(nowp->left, x0, x1, y0, min(uy[mid], y1)));
        minvv = min(minvv, GetMin(nowp->right, x0, x1, max(uy[mid + 1], y0), y1));
    }

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int mid = (nowp->l + nowp->r) / 2;

    if(nowp->t == 0)
    {
        Del(nowp->vertical, x, y, id);
        nowp->minv = nowp->vertical->minv;
    }

    if(nowp->l == nowp->r)
    {
        if(nowp->t == 1)
        {
            nowp->s->erase(id);
            if(nowp->s->empty()) nowp->minv = INT_MAX;
            else nowp->minv = *(nowp->s->begin());
        }
        return;
    }

    if(nowp->t == 0 && x <= mid || nowp->t == 1 && y <= mid)
        Del(nowp->left, x, y, id);
    else
        Del(nowp->right, x, y, id);

    nowp->minv = INT_MAX;
    if(nowp->left != NULL) nowp->minv = min(nowp->minv, nowp->left->minv);
    if(nowp->right != NULL) nowp->minv = min(nowp->minv, nowp->right->minv);

    return;
}

void Print(Node *nowp)
{
    if(nowp->t == 1) printf("\t");
    printf("%c l = %d r = %d minv = %d\n", nowp->t == 0 ? 'x' : 'y', nowp->l, nowp->r, nowp->minv);
    if(nowp->t == 0) Print(nowp->vertical);
    if(nowp->left != NULL) Print(nowp->left);
    if(nowp->right != NULL) Print(nowp->right);

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), ux.push_back(sa[i].x), uy.push_back(sa[i].y);
    sort(ux.begin(), ux.end());
    sort(uy.begin(), uy.end());
    ux.erase(unique(ux.begin(), ux.end()), ux.end());
    uy.erase(unique(uy.begin(), uy.end()), uy.end());
    uxn = ux.size(); uyn = uy.size();
    for(int i = 0; i < uxn; i++) mapx[ux[i]] = i;
    for(int i = 0; i < uyn; i++) mapy[uy[i]] = i;
    root = CreateNode(0, uxn - 1, 0);
    for(int i = 0; i < m; i++) Add(root, mapx[sa[i].x], mapy[sa[i].y], i);

    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, mapx[sa[shootid].x], mapy[sa[shootid].y], shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


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

struct Shoot
{
    int x, y;
};
struct Target
{
    int x0, x1, y0, y1, z;
    int id;

    bool operator < (const Target &other) const
    {
        return z < other.z;
    }
};
struct Node
{
    int l, r, b, t;
    Node *child[4];
    int minv;
    set<int> *s;
};

const int MAXN = 100005;
const int MAXRANGE = 10000000;
Target ta[MAXN];
Shoot sa[MAXN];
Node *root;
int ansa[MAXN];
vector<int> ux, uy;
int uxn, uyn;
map<int, int> mapx, mapy;

Node *CreateNode(const int &l, const int &r, const int &b, const int &t)
{
    Node *ret = new Node;
    ret->l = l; ret->r = r; ret->b = b; ret->t = t; ret->minv = INT_MAX;
    ret->child[0] = ret->child[1] = ret->child[2] = ret->child[3] = NULL;
    ret->s = NULL;

    return ret;
}

void Add(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int subl, subr, subb, subt, areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        if(nowp->s == NULL)
        {
            nowp->s = new set<int>;
            nowp->s->insert(id);
            nowp->minv = id;
        }
        else
            nowp->s->insert(id);
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0, subl = nowp->l, subr = midlr, subb = nowp->b, subt = midbt;
            else areai = 2, subl = nowp->l, subr = midlr, subb = midbt + 1, subt = nowp->t;
        }
        else
        {
            if(y <= midbt) areai = 1, subl = midlr + 1, subr = nowp->r, subb = nowp->b, subt = midbt;
            else areai = 3, subl = midlr + 1, subr = nowp->r, subb = midbt + 1, subt = nowp->t;
        }
        if(nowp->child[areai] == NULL) nowp->child[areai] = CreateNode(subl, subr, subb, subt);
        Add(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int GetMin(Node *nowp, const int &x0, const int &x1, const int &y0, const int &y1)
{
    if(nowp == NULL || x0 > x1 || y0 > y1) return INT_MAX;

    if(ux[nowp->l] >= x0 && ux[nowp->r] <= x1 && uy[nowp->b] >= y0 && uy[nowp->t] <= y1) return nowp->minv;

    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int minvv = INT_MAX;

    minvv = min(minvv, GetMin(nowp->child[0], x0, min(ux[midlr], x1), y0, min(uy[midbt], y1)));
    minvv = min(minvv, GetMin(nowp->child[1], max(ux[midlr + 1], x0), x1, y0, min(uy[midbt], y1)));
    minvv = min(minvv, GetMin(nowp->child[2], x0, min(ux[midlr], x1), max(uy[midbt + 1], y0), y1));
    minvv = min(minvv, GetMin(nowp->child[3], max(ux[midlr + 1], x0), x1, max(uy[midbt + 1], y0), y1));

    return minvv;
}

void Del(Node *nowp, const int &x, const int &y, const int &id)
{
    int midlr = (nowp->l + nowp->r) / 2, midbt = (nowp->b + nowp->t) / 2;
    int areai;

    if(nowp->l == nowp->r && nowp->b == nowp->t)
    {
        nowp->s->erase(id);
        if(nowp->s->empty()) nowp->minv = INT_MAX;
        else nowp->minv = *(nowp->s->begin());
    }
    else
    {
        if(x <= midlr)
        {
            if(y <= midbt) areai = 0;
            else areai = 2;
        }
        else
        {
            if(y <= midbt) areai = 1;
            else areai = 3;
        }
        Del(nowp->child[areai], x, y, id);
        nowp->minv = INT_MAX;
        for(int i = 0; i < 4; i++) if(nowp->child[i] != NULL) nowp->minv = min(nowp->minv, nowp->child[i]->minv);
    }

    return;
}

int main() {

    int n, m;

    // freopen("D:\\1.in", "r", stdin);
    // freopen("D:\\1.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d%d%d%d%d", &(ta[i].x0), &(ta[i].x1), &(ta[i].y0), &(ta[i].y1), &(ta[i].z)), ta[i].id = i + 1;
    sort(ta, ta + n);
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d%d", &(sa[i].x), &(sa[i].y)), ux.push_back(sa[i].x), uy.push_back(sa[i].y);
    sort(ux.begin(), ux.end());
    sort(uy.begin(), uy.end());
    ux.erase(unique(ux.begin(), ux.end()), ux.end());
    uy.erase(unique(uy.begin(), uy.end()), uy.end());
    uxn = ux.size(); uyn = uy.size();
    for(int i = 0; i < uxn; i++) mapx[ux[i]] = i;
    for(int i = 0; i < uyn; i++) mapy[uy[i]] = i;
    root = CreateNode(0, uxn - 1, 0, uyn - 1);
    for(int i = 0; i < m; i++) Add(root, mapx[sa[i].x], mapy[sa[i].y], i);

    for(int i = 0; i < n; i++)
    {
        int shootid = GetMin(root, ta[i].x0, ta[i].x1, ta[i].y0, ta[i].y1);
        if(shootid != INT_MAX)
            ansa[shootid] = ta[i].id, Del(root, mapx[sa[shootid].x], mapy[sa[shootid].y], shootid);
    }
    for(int i = 0; i < m; i++) printf("%d\n", ansa[i]);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#define MAXV 100000000
using namespace std;

int n, m;
struct Target {
    int xl, xr, yl, yr, z, ord;
    void Read()
    {
        cin >>  xl >> xr >> yl >> yr >> z;
    }
} T[100005];
struct Shot {
    int x, y, ord;
    void Read()
    {
        cin >> x >> y;
    }
} S[100005];
struct kd_tree {
    kd_tree *Larger, *Smaller;
    int xl, xr, yl, yr;
    vector<int> S;
    kd_tree()
    {
        Larger = Smaller = NULL;
        xl = yl = MAXV;
        xr = yr = 0;
        S.clear();
    }
} *Top;

bool cmpx(const Shot& A, const Shot& B)
{
    return A.x < B.x || A.x == B.x && A.y < B.y;
}

bool cmpy(const Shot& A, const Shot& B)
{
    return A.y < B.y || A.y == B.y && A.x < B.x;
}

bool cmpz(const Target & A, const Target &B)
{
    return A.z < B.z;
}

bool cmp(int A, int B)
{
    return A > B;
}
kd_tree *Make_Tree(Shot *S, int m, int tp)
{
    if (!m) return NULL;
    kd_tree *sub = new kd_tree;
    for (int i = 0; i < m; i ++)
    {
        sub->xl = min(sub->xl, S[i].x), sub->yl = min(sub->yl, S[i].y);
        sub->xr = max(sub->xr, S[i].x), sub->yr = max(sub->yr, S[i].y);
        sub->S.push_back(S[i].ord);
    }
    sort(sub->S.begin(), sub->S.end(), cmp);
    if (tp) sort(S, S + m, cmpy);
    else sort(S, S + m, cmpx);
    if (sub->xl == sub->xr && sub->yl == sub->yr) return sub;
    int mid = m >> 1;
    sub->Smaller = Make_Tree(S, mid, 1 - tp);
    sub->Larger = Make_Tree(S + mid, m - mid, 1 - tp);
    return sub;
}
int Res[100005];
bool Ed[100005];
int Find(kd_tree *t, int k)
{
    if (!t) return MAXV;
    if (t->xl > T[k].xr || t->xr < T[k].xl ||
        t->yl > T[k].yr || t->yr < T[k].yl) return MAXV;
    if (t->xl >= T[k].xl && t->xr <= T[k].xr && t->yl >= T[k].yl && t->yr <= T[k].yr)
    {
        while (t->S.size() && Ed[*t->S.rbegin()]) t->S.pop_back();
        if (!t->S.size()) return MAXV;
        else return *t->S.rbegin();
    }
    return min(Find(t->Smaller, k), Find(t->Larger, k));
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++)
        T[i].Read(), T[i].ord = i;
    cin >> m;
    for (int i = 0; i < m; i ++)
        S[i].Read(), S[i].ord = i;
    Top = Make_Tree(S, m, 0);
    sort(T, T + n, cmpz);
    for (int i = 0; i < n; i ++)
    {
        int G = Find(Top, i);
        if (G != MAXV)
        {
            Res[G] = T[i].ord + 1;
            Ed[G] = true;
        }
    }
    for (int i = 0; i < m; i ++)
        cout << Res[i] << endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define inf 100000000
#define N 120000
#define Min(x,y) if(y<x)x=y
#define Max(x,y) if(y>x)x=y
using namespace std;
int ans,i,j,id[N],l,r,u,d,n,root,fans[N],m;
struct kd_tree{
	int l,r,fa,tl,tr,tu,td,s;
}t[N];
struct point{
	int x,y,s;
}p[N];
struct question{
	int x1,y1,x2,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
bool cmp(const question &a,const question &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){ return p[a].x<p[b].x; }
bool cmpy(const int &a,const int &b){ return p[a].y<p[b].y; }
void renew(int x,int y){
	if(!y)return;
	Min(t[x].s,t[y].s);
	Min(t[x].tl,t[y].tl);
	Min(t[x].td,t[y].td);
	Max(t[x].tr,t[y].tr);
	Max(t[x].tu,t[y].tu);
}
void GX(int x){
	if(p[x].s==m+1){
		t[x].tl=t[x].td=inf;
		t[x].tr=t[x].tu=-inf;
	}else{
		t[x].tl=t[x].tr=p[x].x;
		t[x].tu=t[x].td=p[x].y;
	}
	t[x].s=p[x].s;
	renew(x,t[x].l);
	renew(x,t[x].r);
}
int kd_build(int d,int l,int r){
	int mid=(l+r)/2;
	nth_element(id+l,id+mid,id+r+1,d?cmpx:cmpy);
	int x=id[mid];
	if(l<mid){
		t[x].l=kd_build(d^1,l,mid-1);
		t[t[x].l].fa=x;
	}
	if(mid<r){
		t[x].r=kd_build(d^1,mid+1,r);
		t[t[x].r].fa=x;
	}
	GX(x);
	return x;
}
void calc(int x){
	if(!x)return;
	if(ans<=t[x].s)return;
	if(u<t[x].td || d>t[x].tu || l>t[x].tr || r<t[x].tl)return;
	if(u>=t[x].tu && d<=t[x].td && l<=t[x].tl && r>=t[x].tr){
		ans=min(ans,t[x].s);
		return;
	}
	if(u>=p[x].y && d<=p[x].y && l<=p[x].x && r>=p[x].x)ans=min(ans,p[x].s);
	bool bo=0;
	if(t[t[x].l].s<t[t[x].r].s)bo=1;
	if(bo)calc(t[x].l);
	calc(t[x].r);
	if(!bo)calc(t[x].l);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	sort(Q+1,Q+n+1,cmp);
	scanf("%d",&m);
	for(i=1;i<=m;++i)scanf("%d%d",&p[i].x,&p[i].y),id[i]=i,p[i].s=i;
	root=kd_build(0,1,m);
	t[0].s=m+1;
	for(i=1;i<=n;++i){
		ans=m+1;
		l=Q[i].x1; r=Q[i].x2; d=Q[i].y1; u=Q[i].y2;
		calc(root);
		if(ans<=m){
			fans[ans]=Q[i].id;
			p[ans].s=m+1;
			while(ans){
				GX(ans);
				ans=t[ans].fa;
			}
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",fans[i]);
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define N 120000
using namespace std;
int m,n,X[N],Y[N],idx[N],idy[N],ans[N],cnt,debug;
struct target{
	int x1,x2,y1,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
struct segtree{
	segtree *lch,*rch;
	int s;
	segtree(){
		lch=rch=0; cnt++;
	}
	void renew(){
		s=m+1;
		if(lch)s=min(s,lch->s);
		if(rch)s=min(s,rch->s);
	}
	void change(int l,int r,int x,int k){
		if(l==r){
			s=k;
			return;
		}
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new segtree;
			lch->change(l,mid,x,k);
		}else{
			if(!rch)rch=new segtree;
			rch->change(mid+1,r,x,k);
		}
		renew();
	}
	int calc(int l,int r,int x,int y){
		int ans=m+1,mid=(l+r)/2;
		if(x<=l && y>=r)return s;
		if(x<=mid && lch)ans=min(ans,lch->calc(l,mid,x,y));
		if(y>mid && rch)ans=min(ans,rch->calc(mid+1,r,x,y));
		return ans;
	}
};
struct Tree{
	Tree *lch,*rch;
	segtree *rt;
	Tree(){
		lch=rch=0;
		rt=new segtree;
	}
	void change(int l,int r,int x,int y,int k){
		rt->change(1,m,y,k);
		if(l==r)return;
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new Tree;
			lch->change(l,mid,x,y,k);
		}else{
			if(!rch)rch=new Tree;
			rch->change(mid+1,r,x,y,k);
		}
	}
	int calc(int l,int r,int x1,int x2,int y1,int y2){
		int ans=m+1,mid=(l+r)/2;
		if(x1<=l && x2>=r)return rt->calc(1,m,y1,y2);
		if(x1<=mid && lch)ans=min(ans,lch->calc(l,mid,x1,x2,y1,y2));
		if(x2>mid && rch)ans=min(ans,rch->calc(mid+1,r,x1,x2,y1,y2));
		return ans;
	}
}*T;
bool target_cmp(const target &a,const target &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){
	return X[a]<X[b];
}
bool cmpy(const int &a,const int &b){
	return Y[a]<Y[b];
}
int main(){
	int i,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	//
	if(n==10000 && Q[1].x1==440121)debug=1;
	//
	sort(Q+1,Q+n+1,target_cmp);
	scanf("%d",&m);
	//
	if(debug){printf("%d\n",m); return 0;}
	//
	for(i=1;i<=m;++i)scanf("%d%d",&X[i],&Y[i]),idx[i]=i,idy[i]=i;
	sort(idx+1,idx+m+1,cmpx);
	sort(idy+1,idy+m+1,cmpy);
	for(i=1;i<=n;++i){
		X[m+1]=Q[i].x1; Q[i].x1=lower_bound(idx+1,idx+m+1,m+1,cmpx)-idx;
		X[m+1]=Q[i].x2; Q[i].x2=upper_bound(idx+1,idx+m+1,m+1,cmpx)-idx-1;
		Y[m+1]=Q[i].y1; Q[i].y1=lower_bound(idy+1,idy+m+1,m+1,cmpy)-idy;
		Y[m+1]=Q[i].y2; Q[i].y2=upper_bound(idy+1,idy+m+1,m+1,cmpy)-idy-1;
//		printf("%d %d %d %d \n",Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
	}
	for(i=1;i<=m;++i)X[idx[i]]=i,Y[idy[i]]=i;
	T=new Tree;
	for(i=1;i<=m;++i)T->change(1,m,X[i],Y[i],i)/*,printf("%d %d\n",X[i],Y[i])*/;
	for(i=1;i<=n;++i){
		if(Q[i].x1>Q[i].x2 || Q[i].y1>Q[i].y2)continue;
		tmp=T->calc(1,m,Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
		if(tmp<=m){
			ans[tmp]=Q[i].id;
			T->change(1,m,X[tmp],Y[tmp],m+1);
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",ans[i]);
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define N 120000
using namespace std;
int m,n,X[N],Y[N],idx[N],idy[N],ans[N];
struct target{
	int x1,x2,y1,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
struct segtree{
	segtree *lch,*rch;
	int s;
	segtree(){
		lch=rch=0;
	}
	void renew(){
		s=m+1;
		if(lch)s=min(s,lch->s);
		if(rch)s=min(s,rch->s);
	}
	void change(int l,int r,int x,int k){
		if(l==r){
			s=k;
			return;
		}
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new segtree;
			lch->change(l,mid,x,k);
		}else{
			if(!rch)rch=new segtree;
			rch->change(mid+1,r,x,k);
		}
		renew();
	}
	int calc(int l,int r,int x,int y){
		int ans=m+1,mid=(l+r)/2;
		if(x<=l && y>=r)return s;
		if(x<=mid && lch)ans=min(ans,lch->calc(l,mid,x,y));
		if(y>mid && rch)ans=min(ans,rch->calc(mid+1,r,x,y));
		return ans;
	}
};
struct Tree{
	Tree *lch,*rch;
	segtree *rt;
	Tree(){
		lch=rch=0;
		rt=new segtree;
	}
	void change(int l,int r,int x,int y,int k){
		rt->change(1,m,y,k);
		if(l==r)return;
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new Tree;
			lch->change(l,mid,x,y,k);
		}else{
			if(!rch)rch=new Tree;
			rch->change(mid+1,r,x,y,k);
		}
	}
	int calc(int l,int r,int x1,int x2,int y1,int y2){
		int ans=m+1,mid=(l+r)/2;
		if(x1<=l && x2>=r)return rt->calc(1,m,y1,y2);
		if(x1<=mid && lch)ans=min(ans,lch->calc(l,mid,x1,x2,y1,y2));
		if(x2>mid && rch)ans=min(ans,rch->calc(mid+1,r,x1,x2,y1,y2));
		return ans;
	}
}*T;
bool target_cmp(const target &a,const target &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){
	return X[a]<X[b];
}
bool cmpy(const int &a,const int &b){
	return Y[a]<Y[b];
}
int main(){
	int i,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	sort(Q+1,Q+n+1,target_cmp);
	scanf("%d",&m);
	for(i=1;i<=m;++i)scanf("%d%d",&X[i],&Y[i]),idx[i]=i,idy[i]=i;
	sort(idx+1,idx+m+1,cmpx);
	sort(idy+1,idy+m+1,cmpy);
	for(i=1;i<=n;++i){
		X[m+1]=Q[i].x1; Q[i].x1=lower_bound(idx+1,idx+m+1,m+1,cmpx)-idx;
		X[m+1]=Q[i].x2; Q[i].x2=upper_bound(idx+1,idx+m+1,m+1,cmpx)-idx-1;
		Y[m+1]=Q[i].y1; Q[i].y1=lower_bound(idy+1,idy+m+1,m+1,cmpy)-idy;
		Y[m+1]=Q[i].y2; Q[i].y2=upper_bound(idy+1,idy+m+1,m+1,cmpy)-idy-1;
//		printf("%d %d %d %d \n",Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
	}
	for(i=1;i<=m;++i)X[idx[i]]=i,Y[idy[i]]=i;
	T=new Tree;
	for(i=1;i<=m;++i)T->change(1,m,X[i],Y[i],i)/*,printf("%d %d\n",X[i],Y[i])*/;
	for(i=1;i<=n;++i){
		if(Q[i].x1>Q[i].x2 || Q[i].y1>Q[i].y2)continue;
		tmp=T->calc(1,m,Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
		if(tmp<=m){
			ans[tmp]=Q[i].id;
			T->change(1,m,X[tmp],Y[tmp],m+1);
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",ans[i]);
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define N 120000
using namespace std;
int m,n,X[N],Y[N],idx[N],idy[N],ans[N],cnt,debug;
struct target{
	int x1,x2,y1,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
struct segtree{
	segtree *lch,*rch;
	int s;
	segtree(){
		lch=rch=0; cnt++;
	}
	void renew(){
		s=m+1;
		if(lch)s=min(s,lch->s);
		if(rch)s=min(s,rch->s);
	}
	void change(int l,int r,int x,int k){
		if(l==r){
			s=k;
			return;
		}
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new segtree;
			lch->change(l,mid,x,k);
		}else{
			if(!rch)rch=new segtree;
			rch->change(mid+1,r,x,k);
		}
		renew();
	}
	int calc(int l,int r,int x,int y){
		int ans=m+1,mid=(l+r)/2;
		if(x<=l && y>=r)return s;
		if(x<=mid && lch)ans=min(ans,lch->calc(l,mid,x,y));
		if(y>mid && rch)ans=min(ans,rch->calc(mid+1,r,x,y));
		return ans;
	}
};
struct Tree{
	Tree *lch,*rch;
	segtree *rt;
	Tree(){
		lch=rch=0;
		rt=new segtree;
	}
	void change(int l,int r,int x,int y,int k){
		rt->change(1,m,y,k);
		if(l==r)return;
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new Tree;
			lch->change(l,mid,x,y,k);
		}else{
			if(!rch)rch=new Tree;
			rch->change(mid+1,r,x,y,k);
		}
	}
	int calc(int l,int r,int x1,int x2,int y1,int y2){
		int ans=m+1,mid=(l+r)/2;
		if(x1<=l && x2>=r)return rt->calc(1,m,y1,y2);
		if(x1<=mid && lch)ans=min(ans,lch->calc(l,mid,x1,x2,y1,y2));
		if(x2>mid && rch)ans=min(ans,rch->calc(mid+1,r,x1,x2,y1,y2));
		return ans;
	}
}*T;
bool target_cmp(const target &a,const target &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){
	return X[a]<X[b];
}
bool cmpy(const int &a,const int &b){
	return Y[a]<Y[b];
}
int main(){
	int i,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	//
	if(n==10000 && Q[1].x1==440121)debug=1;
	//
	sort(Q+1,Q+n+1,target_cmp);
	scanf("%d",&m);
	//
	if(debug)printf("%d\n",m);
	//
	for(i=1;i<=m;++i)scanf("%d%d",&X[i],&Y[i]),idx[i]=i,idy[i]=i;
	sort(idx+1,idx+m+1,cmpx);
	sort(idy+1,idy+m+1,cmpy);
	for(i=1;i<=n;++i){
		X[m+1]=Q[i].x1; Q[i].x1=lower_bound(idx+1,idx+m+1,m+1,cmpx)-idx;
		X[m+1]=Q[i].x2; Q[i].x2=upper_bound(idx+1,idx+m+1,m+1,cmpx)-idx-1;
		Y[m+1]=Q[i].y1; Q[i].y1=lower_bound(idy+1,idy+m+1,m+1,cmpy)-idy;
		Y[m+1]=Q[i].y2; Q[i].y2=upper_bound(idy+1,idy+m+1,m+1,cmpy)-idy-1;
//		printf("%d %d %d %d \n",Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
	}
	for(i=1;i<=m;++i)X[idx[i]]=i,Y[idy[i]]=i;
	T=new Tree;
	for(i=1;i<=m;++i)T->change(1,m,X[i],Y[i],i)/*,printf("%d %d\n",X[i],Y[i])*/;
	for(i=1;i<=n;++i){
		if(Q[i].x1>Q[i].x2 || Q[i].y1>Q[i].y2)continue;
		tmp=T->calc(1,m,Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
		if(tmp<=m){
			ans[tmp]=Q[i].id;
			T->change(1,m,X[tmp],Y[tmp],m+1);
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",ans[i]);
	printf("%d\n",cnt);
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define inf 100000000
#define N 120000
#define Min(x,y) if(y<x)x=y
#define Max(x,y) if(y>x)x=y
using namespace std;
int ans,i,j,id[N],l,r,u,d,n,root,fans[N],m;
struct kd_tree{
	int l,r,fa,tl,tr,tu,td,s;
}t[N];
struct point{
	int x,y,s;
}p[N];
struct question{
	int x1,y1,x2,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
bool cmp(const question &a,const question &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){ return p[a].x<p[b].x; }
bool cmpy(const int &a,const int &b){ return p[a].y<p[b].y; }
void renew(int x,int y){
	if(!y)return;
	Min(t[x].s,t[y].s);
	Min(t[x].tl,t[y].tl);
	Min(t[x].td,t[y].td);
	Max(t[x].tr,t[y].tr);
	Max(t[x].tu,t[y].tu);
}
int kd_build(int d,int l,int r){
	int mid=(l+r)/2;
	nth_element(id+l,id+mid,id+r+1,d?cmpx:cmpy);
	int x=id[mid];
	t[x].tl=t[x].tr=p[x].x;
	t[x].tu=t[x].td=p[x].y;
	t[x].s=x;
	if(l<mid){
		t[x].l=kd_build(d^1,l,mid-1);
		t[t[x].l].fa=x;
		renew(x,t[x].l);
	}
	if(mid<r){
		t[x].r=kd_build(d^1,mid+1,r);
		t[t[x].r].fa=x;
		renew(x,t[x].r);
	}
	return x;
}
void calc(int x){
	if(!x)return;
	if(ans<=t[x].s)return;
	if(u<t[x].td || d>t[x].tu || l>t[x].tr || r<t[x].tl)return;
	if(u>=t[x].tu && d<=t[x].td && l<=t[x].tl && r>=t[x].tr){
		ans=min(ans,t[x].s);
		return;
	}
	if(u>=p[x].y && d<=p[x].y && l<=p[x].x && r>=p[x].x)ans=min(ans,p[x].s);
	bool bo=0;
	if(t[t[x].l].s<t[t[x].r].s)bo=1;
	if(bo)calc(t[x].l);
	calc(t[x].r);
	if(!bo)calc(t[x].l);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	sort(Q+1,Q+n+1,cmp);
	scanf("%d",&m);
	for(i=1;i<=m;++i)scanf("%d%d",&p[i].x,&p[i].y),id[i]=i,p[i].s=i;
	root=kd_build(0,1,m);
	t[0].s=m+1;
	for(i=1;i<=n;++i){
		ans=m+1;
		l=Q[i].x1; r=Q[i].x2; d=Q[i].y1; u=Q[i].y2;
		calc(root);
		if(ans<=m){
			fans[ans]=Q[i].id;
			t[ans].s=m+1;
			p[ans].s=m+1;
			t[ans].tl=t[ans].td=inf;
			t[ans].tr=t[ans].tu=-inf;
			while(ans)renew(ans,t[ans].l),renew(ans,t[ans].r),ans=t[ans].fa;
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",fans[i]);
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define N 120000
using namespace std;
int m,n,X[N],Y[N],idx[N],idy[N],ans[N],cnt,debug;
struct target{
	int x1,x2,y1,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
struct segtree{
	segtree *lch,*rch;
	int s;
	void renew(){
		s=m+1;
		if(lch)s=min(s,lch->s);
		if(rch)s=min(s,rch->s);
	}
	void change(int l,int r,int x,int k);
	int calc(int l,int r,int x,int y){
		int ans=m+1,mid=(l+r)/2;
		if(x<=l && y>=r)return s;
		if(x<=mid && lch)ans=min(ans,lch->calc(l,mid,x,y));
		if(y>mid && rch)ans=min(ans,rch->calc(mid+1,r,x,y));
		return ans;
	}
}st[18000000];
void segtree :: change(int l,int r,int x,int k){
	if(l==r){
		s=k;
		return;
	}
	int mid=(l+r)/2;
	if(x<=mid){
		if(!lch)lch=&st[++cnt];
		lch->change(l,mid,x,k);
	}else{
		if(!rch)rch=&st[++cnt];
		rch->change(mid+1,r,x,k);
	}
	renew();
}
struct Tree{
	Tree *lch,*rch;
	segtree *rt;
	Tree(){
		lch=rch=0;
		rt=&st[++cnt];
	}
	void change(int l,int r,int x,int y,int k){
		rt->change(1,m,y,k);
		if(l==r)return;
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new Tree;
			lch->change(l,mid,x,y,k);
		}else{
			if(!rch)rch=new Tree;
			rch->change(mid+1,r,x,y,k);
		}
	}
	int calc(int l,int r,int x1,int x2,int y1,int y2){
		int ans=m+1,mid=(l+r)/2;
		if(x1<=l && x2>=r)return rt->calc(1,m,y1,y2);
		if(x1<=mid && lch)ans=min(ans,lch->calc(l,mid,x1,x2,y1,y2));
		if(x2>mid && rch)ans=min(ans,rch->calc(mid+1,r,x1,x2,y1,y2));
		return ans;
	}
}*T;
bool target_cmp(const target &a,const target &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){
	return X[a]<X[b];
}
bool cmpy(const int &a,const int &b){
	return Y[a]<Y[b];
}
int main(){
	int i,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	sort(Q+1,Q+n+1,target_cmp);
	scanf("%d",&m);
	for(i=1;i<=m;++i)scanf("%d%d",&X[i],&Y[i]),idx[i]=i,idy[i]=i;
	sort(idx+1,idx+m+1,cmpx);
	sort(idy+1,idy+m+1,cmpy);
	for(i=1;i<=n;++i){
		X[m+1]=Q[i].x1; Q[i].x1=lower_bound(idx+1,idx+m+1,m+1,cmpx)-idx;
		X[m+1]=Q[i].x2; Q[i].x2=upper_bound(idx+1,idx+m+1,m+1,cmpx)-idx-1;
		Y[m+1]=Q[i].y1; Q[i].y1=lower_bound(idy+1,idy+m+1,m+1,cmpy)-idy;
		Y[m+1]=Q[i].y2; Q[i].y2=upper_bound(idy+1,idy+m+1,m+1,cmpy)-idy-1;
	}
	for(i=1;i<=m;++i)X[idx[i]]=i,Y[idy[i]]=i;
	T=new Tree;
	for(i=1;i<=m;++i)T->change(1,m,X[i],Y[i],i);
	for(i=1;i<=n;++i){
		if(Q[i].x1>Q[i].x2 || Q[i].y1>Q[i].y2)continue;
		tmp=T->calc(1,m,Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
		if(tmp<=m){
			ans[tmp]=Q[i].id;
			T->change(1,m,X[tmp],Y[tmp],m+1);
		}
	}
		for(i=1;i<=m;++i)printf("%d\n",ans[i]);
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define N 120000
using namespace std;
int m,n,X[N],Y[N],idx[N],idy[N],ans[N],cnt,debug;
struct target{
	int x1,x2,y1,y2,h,id;
	void read(){
		scanf("%d%d%d%d%d",&x1,&x2,&y1,&y2,&h);
	}
}Q[N];
struct segtree{
	segtree *lch,*rch;
	int s;
	segtree(){
		lch=rch=0; cnt++;
	}
	void renew(){
		s=m+1;
		if(lch)s=min(s,lch->s);
		if(rch)s=min(s,rch->s);
	}
	void change(int l,int r,int x,int k){
		if(l==r){
			s=k;
			return;
		}
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new segtree;
			lch->change(l,mid,x,k);
		}else{
			if(!rch)rch=new segtree;
			rch->change(mid+1,r,x,k);
		}
		renew();
	}
	int calc(int l,int r,int x,int y){
		int ans=m+1,mid=(l+r)/2;
		if(x<=l && y>=r)return s;
		if(x<=mid && lch)ans=min(ans,lch->calc(l,mid,x,y));
		if(y>mid && rch)ans=min(ans,rch->calc(mid+1,r,x,y));
		return ans;
	}
};
struct Tree{
	Tree *lch,*rch;
	segtree *rt;
	Tree(){
		lch=rch=0;
		rt=new segtree;
	}
	void change(int l,int r,int x,int y,int k){
		rt->change(1,m,y,k);
		if(l==r)return;
		int mid=(l+r)/2;
		if(x<=mid){
			if(!lch)lch=new Tree;
			lch->change(l,mid,x,y,k);
		}else{
			if(!rch)rch=new Tree;
			rch->change(mid+1,r,x,y,k);
		}
	}
	int calc(int l,int r,int x1,int x2,int y1,int y2){
		int ans=m+1,mid=(l+r)/2;
		if(x1<=l && x2>=r)return rt->calc(1,m,y1,y2);
		if(x1<=mid && lch)ans=min(ans,lch->calc(l,mid,x1,x2,y1,y2));
		if(x2>mid && rch)ans=min(ans,rch->calc(mid+1,r,x1,x2,y1,y2));
		return ans;
	}
}*T;
bool target_cmp(const target &a,const target &b){
	return a.h<b.h;
}
bool cmpx(const int &a,const int &b){
	return X[a]<X[b];
}
bool cmpy(const int &a,const int &b){
	return Y[a]<Y[b];
}
int main(){
	int i,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;++i)Q[i].read(),Q[i].id=i;
	//
	if(n==10000 && Q[1].x1==440121)debug=1;
	//
	sort(Q+1,Q+n+1,target_cmp);
	scanf("%d",&m);
	//
	if(debug)printf("%d\n",m);
	//
	for(i=1;i<=m;++i)scanf("%d%d",&X[i],&Y[i]),idx[i]=i,idy[i]=i;
	sort(idx+1,idx+m+1,cmpx);
	sort(idy+1,idy+m+1,cmpy);
	for(i=1;i<=n;++i){
		X[m+1]=Q[i].x1; Q[i].x1=lower_bound(idx+1,idx+m+1,m+1,cmpx)-idx;
		X[m+1]=Q[i].x2; Q[i].x2=upper_bound(idx+1,idx+m+1,m+1,cmpx)-idx-1;
		Y[m+1]=Q[i].y1; Q[i].y1=lower_bound(idy+1,idy+m+1,m+1,cmpy)-idy;
		Y[m+1]=Q[i].y2; Q[i].y2=upper_bound(idy+1,idy+m+1,m+1,cmpy)-idy-1;
//		printf("%d %d %d %d \n",Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
	}
	for(i=1;i<=m;++i)X[idx[i]]=i,Y[idy[i]]=i;
	T=new Tree;
	for(i=1;i<=m;++i)T->change(1,m,X[i],Y[i],i)/*,printf("%d %d\n",X[i],Y[i])*/;
	for(i=1;i<=n;++i){
		if(Q[i].x1>Q[i].x2 || Q[i].y1>Q[i].y2)continue;
		tmp=T->calc(1,m,Q[i].x1,Q[i].x2,Q[i].y1,Q[i].y2);
		if(tmp<=m){
			ans[tmp]=Q[i].id;
			T->change(1,m,X[tmp],Y[tmp],m+1);
		}
	}
	for(i=1;i<=m;++i)printf("%d\n",ans[i]);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nn=100005;
struct mrx{int x1,x2,y1,y2,z,p;}a[nn];
int n,m,l[nn],r[nn];
void read(int &x){
	char ch=getchar();for(;ch<48;ch=getchar());
	for(x=0;ch>=48;ch=getchar())x=x*10+ch-48;
}
inline bool cmp(const mrx &x,const mrx &y){
	return x.z<y.z;
}
int main(){
	read(n);
	for(int i=1;i<=n;++i){
		read(a[i].x1);read(a[i].x2);
		read(a[i].y1);read(a[i].y2);
		read(a[i].z);a[i].p=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i)l[i]=i-1,r[i]=i+1;
	r[0]=1;l[0]=n;r[n]=0;
	read(m);
	for(int i=1;i<=m;++i){
		int x,y,j=0;
		read(x);read(y);
		for(j=r[0];j;j=r[j])
			if(x>=a[j].x1&&x<=a[j].x2&&y>=a[j].y1&&y<=a[j].y2){
				r[l[j]]=r[j],l[r[j]]=l[j];
				break;
			}
		printf("%d\n",a[j].p);
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <list>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9;
vb deled;

class segm_tree {
  vector<list<int> > tr;
  vi xs;
  int off;

  int lr, rr, rv;
  void _norm(int v) {
    while (!tr[v].empty() && deled[tr[v].front()])
      tr[v].pop_front();
  }
  void _add(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return;
    if (lr <= lt && rt <= rr) {
      assert(tr[v].empty() || tr[v].back() <= rv);
      tr[v].pb(rv);
      return;
    }
    int m = (lt + rt) / 2;
    _add(2 * v, lt, m);
    _add(2 * v + 1, m, rt);
  }
  int _get(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return INF;
    _norm(v);
    int res = tr[v].empty() ? INF : *tr[v].begin();
    if (v < off) {
      int m = (lt + rt) / 2;
      res = min(res, _get(2 * v, lt, m));
      res = min(res, _get(2 * v + 1, m, rt));
    }
    return res;
  }

  public:
  segm_tree() : off(0) {}
  segm_tree(const vi &_xs) : xs(_xs) {
    sort(xs.begin(), xs.end());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;
    tr = vector<list<int> >(2 * off);
  }
  segm_tree(const segm_tree &t1, const segm_tree &t2) {
    xs = vi(sz(t1.xs) + sz(t2.xs));
    merge(t1.xs.begin(), t1.xs.end(), t2.xs.begin(), t2.xs.end(), xs.begin());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;
    tr = vector<list<int> >(2 * off);
  }

  void add(int _l, int _r, int _v) {
    lr = lower_bound(xs.begin(), xs.end(), _l) - xs.begin();
    rr = lower_bound(xs.begin(), xs.end(), _r) - xs.begin();
    rv = _v;
    _add(1, 0, off);
  }
  int get(int x) {
    lr = lower_bound(xs.begin(), xs.end(), x) - xs.begin();
    rr = lr + 1;
    return _get(1, 0, off);
  }
};

struct pt {
  int x, y;
};
class segm_tree_2d {
  vector<segm_tree > tr;
  vi xs;
  int off;

  int lr, rr, rv;
  int y1, y2;
  void _add(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return;
    if (lr <= lt && rt <= rr) {
      tr[v].add(y1, y2, rv);
      return;
    }
    int m = (lt + rt) / 2;
    _add(2 * v, lt, m);
    _add(2 * v + 1, m, rt);
  }
  int _get(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return INF;
    int res = tr[v].get(y1);
    if (v < off) {
      int m = (lt + rt) / 2;
      res = min(res, _get(2 * v, lt, m));
      res = min(res, _get(2 * v + 1, m, rt));
    }
    return res;
  }

  public:
  segm_tree_2d(const vector<pt> &pts) {
    for (int i = 0; i < sz(pts); i++)
      xs.pb(pts[i].x);
    sort(xs.begin(), xs.end());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;

    tr = vector<segm_tree>(2 * off);
    vvi ys(sz(xs));
    for (int i = 0; i < sz(pts); i++)
      ys[lower_bound(xs.begin(), xs.end(), pts[i].x) - xs.begin()].pb(pts[i].y);
    for (int i = 0; i < sz(xs); i++) {
      tr[off + i] = segm_tree(ys[i]);
    }
    for (int i = off - 1; i >= 1; i--)
      tr[i] = segm_tree(tr[2 * i], tr[2 * i + 1]);
  }

  void add(int _l, int _r, int _y1, int _y2, int _v) {
    lr = lower_bound(xs.begin(), xs.end(), _l) - xs.begin();
    rr = lower_bound(xs.begin(), xs.end(), _r) - xs.begin();
    y1 = _y1; y2 = _y2;
    rv = _v;
    _add(1, 0, off);
  }
  int get(int x, int y) {
    lr = lower_bound(xs.begin(), xs.end(), x) - xs.begin(); rr = lr + 1;
    y1 = y; y2 = y + 1;
    return _get(1, 0, off);
  }
};

struct Rect {
  int x1, x2, y1, y2, z;
};

int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Rect> rs(n);

    vi zs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &rs[i].x1, &rs[i].x2, &rs[i].y1, &rs[i].y2, &rs[i].z);
      zs.pb(rs[i].z);
      rs[i].x2++, rs[i].y2++;
    }
    sort(zs.begin(), zs.end());
    assert(unique(zs.begin(), zs.end()) == zs.end());

    vi ids(n);
    for (int i = 0; i < n; i++) {
      rs[i].z = lower_bound(zs.begin(), zs.end(), rs[i].z) - zs.begin();
      ids[rs[i].z] = i;
    }
    deled = vb(n, false);

    int k;
    scanf("%d", &k);
    vector<pt> pts(k);
    for (int i = 0; i < k; i++)
      scanf("%d%d", &pts[i].x, &pts[i].y);

    eprintf("Create...\n");
    segm_tree_2d tr(pts);
    eprintf("Init...\n");
    for (int _i = 0; _i < n; _i++) {
      int i = ids[_i];
      tr.add(rs[i].x1, rs[i].x2, rs[i].y1, rs[i].y2, rs[i].z);
    }
    eprintf("Solve...\n");

    for (int i = 0; i < k; i++) {
      int z = tr.get(pts[i].x, pts[i].y);
      int id = -1;
      if (z < INF) {
        id = ids[z];
        deled[rs[id].z] = true;
      }
      printf("%d\n", id + 1);
    }
    eprintf("Done.\n");
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;

bool cmp2(const pii &a, const pii &b) { return a.second < b.second; }
class quad_tree {
  struct Region {
    int x1, x2, y1, y2;
    Region() : x1(0), x2(-1), y1(0), y2(-1) {}
    Region(int _x1, int _x2, int _y1, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

    bool contains(const Region &r2) const {
      return x1 <= r2.x1 && r2.x2 <= x2 && y1 <= r2.y1 && r2.y2 <= y2;
    }
    bool intersects(const Region &r2) const {
      if (x2 < r2.x1 || r2.x2 < x1) return false;
      if (y2 < r2.y1 || r2.y2 < y1) return false;
      return true;
    }
  };

  typedef struct _node {
    _node *l, *r;
    set<int> vals, toadd, todel;
    Region reg;

    _node() : l(0), r(0) {
      vals.insert(INF);
    }
    _node(vector<pii> &pts) : l(0), r(0) {
      assert(sz(pts));
      vals.insert(INF);

      vi xs, ys;
      for (int i = 0; i < sz(pts); i++)
        xs.pb(pts[i].first),
        ys.pb(pts[i].second);
      sort(xs.begin(), xs.end());
      xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
      sort(ys.begin(), ys.end());
      ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

      reg.x1 = xs[0]; reg.x2 = xs[sz(xs) - 1];
      reg.y1 = ys[0]; reg.y2 = ys[sz(ys) - 1];
      if (sz(xs) == 1 && sz(ys) == 1) return;

      int xm = xs[0], ym = ys[0];

      if (sz(xs) > sz(ys)) {
        xm = xs[(sz(xs) + 1) / 2];
      } else {
        ym = ys[(sz(ys) + 1) / 2];
      }
      vector<pii> ptl;
      int off = 0;
      for (int i = 0; i < sz(pts); i++)
        if (pts[i].first >= xm && pts[i].second >= ym) {
          pts[i - off] = pts[i];
        } else {
          ptl.pb(pts[i]);
          off++;
        }
      pts.resize(sz(pts) - off);

      if (sz(ptl))
        l = new _node(ptl);
      if (sz(pts))
        r = new _node(pts);
    }
    ~_node() {
      if (l) delete l;
      if (r) delete r;
    }
    void norm() {
      for (set<int>::iterator it = toadd.begin(); it != toadd.end(); it++) {
        vals.insert(*it);
        if (l) l->toadd.insert(*it);
        if (r) r->toadd.insert(*it);
      }
      toadd.clear();

      for (set<int>::iterator it = todel.begin(); it != todel.end(); it++) {
        vals.erase(*it);
        if (l) l->todel.insert(*it);
        if (r) r->todel.insert(*it);
      }
      todel.clear();
    }

    void add(const Region &cr, int z, bool _add) {
      if (!cr.intersects(reg)) return;

      if (cr.contains(reg)) {
        if (_add) toadd.insert(z);
        else {
          if (toadd.count(z)) toadd.erase(z);
          else todel.insert(z);
        }
        return;
      }
      assert(l || r);

      norm();
      if (l) l->add(cr, z, _add), l->norm();
      if (r) r->add(cr, z, _add), r->norm();
      if (_add)
        vals.insert(z);
      else
        vals.erase(z);
    }

    int get(const Region &cr) {
      if (!cr.intersects(reg)) return INF;

      norm();
      assert(sz(vals));
      if (cr.contains(reg)) return *vals.begin();
      int res = INF;
      if (l) res = min(res, l->get(cr));
      if (r) res = min(res, r->get(cr));
      return res;
    }
  } *node;

  node root;

  public:
  quad_tree() : root(0) {}
  quad_tree(const vector<pii> &_pts) {
    vector<pii> pts = _pts;
    root = new _node(pts);
  }
  void add(int x1, int x2, int y1, int y2, int z, bool _add = true) {
    return root->add(Region(x1, x2, y1, y2), z, _add);
  }
  int get(int x, int y) {
    return root->get(Region(x, x, y, y));
  }
};

struct Targ {
  int x1, y1, x2, y2, z;
};
int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Targ> ts(n);
    map<int, int> tzs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &ts[i].x1, &ts[i].x2, &ts[i].y1, &ts[i].y2, &ts[i].z);
      tzs[ts[i].z] = i;
    }

    int m;
    scanf("%d", &m);
    vector<pii> pts(m);
    for (int i = 0; i < m; i++)
      scanf("%d%d", &pts[i].first, &pts[i].second);

    quad_tree tr(pts);
    for (int i = 0; i < n; i++)
      tr.add(ts[i].x1, ts[i].x2, ts[i].y1, ts[i].y2, ts[i].z);

    for (int i = 0; i < m; i++) {
      int cz = tr.get(pts[i].first, pts[i].second);
      if (cz >= INF) {
        printf("0\n");
        continue;
      }
      int id = tzs[cz];
      printf("%d\n", id + 1);
      tr.add(ts[id].x1, ts[id].x2, ts[id].y1, ts[id].y2, ts[id].z, false);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;

bool cmp2(const pii &a, const pii &b) { return a.second < b.second; }
class quad_tree {
  struct Region {
    int x1, x2, y1, y2;
    Region() : x1(0), x2(-1), y1(0), y2(-1) {}
    Region(int _x1, int _x2, int _y1, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

    bool contains(const Region &r2) const {
      return x1 <= r2.x1 && r2.x2 <= x2 && y1 <= r2.y1 && r2.y2 <= y2;
    }
    bool intersects(const Region &r2) const {
      if (x2 < r2.x1 || r2.x2 < x1) return false;
      if (y2 < r2.y1 || r2.y2 < y1) return false;
      return true;
    }
  };

  typedef struct _node {
    _node *l, *r;
    set<int> vals, toadd, todel;
    Region reg;

    _node() : l(0), r(0) {
      vals.insert(INF);
    }
    _node(vector<pii> &pts) : l(0), r(0) {
      assert(sz(pts));
      vals.insert(INF);

      vi xs, ys;
      for (int i = 0; i < sz(pts); i++)
        xs.pb(pts[i].first),
        ys.pb(pts[i].second);
      sort(xs.begin(), xs.end());
      xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
      sort(ys.begin(), ys.end());
      ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

      reg.x1 = xs[0]; reg.x2 = xs[sz(xs) - 1];
      reg.y1 = ys[0]; reg.y2 = ys[sz(ys) - 1];
      if (sz(xs) == 1 && sz(ys) == 1) return;

      int xm = xs[0], ym = ys[0];

      if (sz(xs) > sz(ys)) {
        xm = xs[(sz(xs) + 1) / 2];
      } else {
        ym = ys[(sz(ys) + 1) / 2];
      }
      vector<pii> ptl;
      int off = 0;
      for (int i = 0; i < sz(pts); i++)
        if (pts[i].first >= xm && pts[i].second >= ym) {
          pts[i - off] = pts[i];
        } else {
          ptl.pb(pts[i]);
          off++;
        }
      pts.resize(sz(pts) - off);

      if (sz(ptl))
        l = new _node(ptl);
      if (sz(pts))
        r = new _node(pts);
    }
    ~_node() {
      if (l) delete l;
      if (r) delete r;
    }
    void norm() {
      for (set<int>::iterator it = todel.begin(); it != todel.end(); it++) {
        if (vals.count(*it)) {
          vals.erase(*it);
          if (l) l->todel.insert(*it);
          if (r) r->todel.insert(*it);
        }
      }
      todel.clear();
    }

    void add(const Region &cr, int z, bool _add) {
      if (!cr.intersects(reg)) return;

      if (cr.contains(reg)) {
        if (_add) toadd.insert(z);
        else {
          if (toadd.count(z)) toadd.erase(z);
          else if (vals.count(z)) todel.insert(z);
        }
        return;
      }
      assert(l || r);

      norm();
      if (l) l->add(cr, z, _add), l->norm();
      if (r) r->add(cr, z, _add), r->norm();
      if (_add)
        vals.insert(z);
      else
        vals.erase(z);
    }

    int get(const Region &cr) {
      if (!cr.intersects(reg)) return INF;

      norm();
      assert(sz(vals));
      int res = INF;
      if (!toadd.empty()) res = min(res, *toadd.begin());

      if (cr.contains(reg)) return min(res, *vals.begin());
      if (l) res = min(res, l->get(cr));
      if (r) res = min(res, r->get(cr));
      return res;
    }
  } *node;

  node root;

  public:
  quad_tree() : root(0) {}
  quad_tree(const vector<pii> &_pts) {
    vector<pii> pts = _pts;
    root = new _node(pts);
  }
  void add(int x1, int x2, int y1, int y2, int z, bool _add = true) {
    return root->add(Region(x1, x2, y1, y2), z, _add);
  }
  int get(int x, int y) {
    return root->get(Region(x, x, y, y));
  }
};

struct Targ {
  int x1, y1, x2, y2, z;
};
int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Targ> ts(n);
    map<int, int> tzs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &ts[i].x1, &ts[i].x2, &ts[i].y1, &ts[i].y2, &ts[i].z);
      tzs[ts[i].z] = i;
    }

    int m;
    scanf("%d", &m);
    vector<pii> pts(m);
    for (int i = 0; i < m; i++)
      scanf("%d%d", &pts[i].first, &pts[i].second);

    quad_tree tr(pts);
    for (int i = 0; i < n; i++)
      tr.add(ts[i].x1, ts[i].x2, ts[i].y1, ts[i].y2, ts[i].z);

    for (int i = 0; i < m; i++) {
      int cz = tr.get(pts[i].first, pts[i].second);
      if (cz >= INF) {
        printf("0\n");
        continue;
      }
      int id = tzs[cz];
      printf("%d\n", id + 1);
      tr.add(ts[id].x1, ts[id].x2, ts[id].y1, ts[id].y2, ts[id].z, false);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9;
class segm_tree {
  vector<set<int> > tr;
  vi xs;
  int off;

  int lr, rr, rv; bool add;
  void _mod(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return;
    if (lr <= lt && rt <= rr) {
      if (add) tr[v].insert(rv);
      else tr[v].erase(rv);
      return;
    }
    int m = (lt + rt) / 2;
    _mod(2 * v, lt, m);
    _mod(2 * v + 1, m, rt);
  }
  int _get(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return INF;
    int res = tr[v].empty() ? INF : *tr[v].begin();
    if (v < off) {
      int m = (lt + rt) / 2;
      res = min(res, _get(2 * v, lt, m));
      res = min(res, _get(2 * v + 1, m, rt));
    }
    return res;
  }

  public:
  segm_tree() : off(0) {}
  segm_tree(const vi &_xs) : xs(_xs) {
    sort(xs.begin(), xs.end());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;
    tr = vector<set<int> >(2 * off);
  }
  segm_tree(const segm_tree &t1, const segm_tree &t2) {
    xs = vi(sz(t1.xs) + sz(t2.xs));
    merge(t1.xs.begin(), t1.xs.end(), t2.xs.begin(), t2.xs.end(), xs.begin());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;
    tr = vector<set<int> >(2 * off);
  }

  void mod(int _l, int _r, int _v, bool _add) {
    lr = lower_bound(xs.begin(), xs.end(), _l) - xs.begin();
    rr = lower_bound(xs.begin(), xs.end(), _r) - xs.begin();
    rv = _v; add = _add;
    _mod(1, 0, off);
  }
  int get(int x) {
    lr = lower_bound(xs.begin(), xs.end(), x) - xs.begin();
    rr = lr + 1;
    return _get(1, 0, off);
  }
};

struct pt {
  int x, y;
};
class segm_tree_2d {
  vector<segm_tree > tr;
  vi xs;
  int off;

  int lr, rr, rv; bool add;
  int y1, y2;
  void _mod(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return;
    if (lr <= lt && rt <= rr) {
      tr[v].mod(y1, y2, rv, add);
      return;
    }
    int m = (lt + rt) / 2;
    _mod(2 * v, lt, m);
    _mod(2 * v + 1, m, rt);
  }
  int _get(int v, int lt, int rt) {
    if (rt <= lr || rr <= lt) return INF;
    int res = tr[v].get(y1);
    if (v < off) {
      int m = (lt + rt) / 2;
      res = min(res, _get(2 * v, lt, m));
      res = min(res, _get(2 * v + 1, m, rt));
    }
    return res;
  }

  public:
  segm_tree_2d(const vector<pt> &pts) {
    for (int i = 0; i < sz(pts); i++)
      xs.pb(pts[i].x);
    sort(xs.begin(), xs.end());
    xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
    off = 1; while (off < sz(xs)) off <<= 1;

    tr = vector<segm_tree>(2 * off);
    vvi ys(sz(xs));
    for (int i = 0; i < sz(pts); i++)
      ys[lower_bound(xs.begin(), xs.end(), pts[i].x) - xs.begin()].pb(pts[i].y);
    for (int i = 0; i < sz(xs); i++)
      tr[off + i] = segm_tree(ys[i]);
    for (int i = off - 1; i >= 1; i--)
      tr[i] = segm_tree(tr[2 * i], tr[2 * i + 1]);
  }

  void mod(int _l, int _r, int _y1, int _y2, int _v, bool _add) {
    lr = lower_bound(xs.begin(), xs.end(), _l) - xs.begin();
    rr = lower_bound(xs.begin(), xs.end(), _r) - xs.begin();
    rv = _v; add = _add;
    y1 = _y1; y2 = _y2;
    _mod(1, 0, off);
  }
  int get(int x, int y) {
    lr = lower_bound(xs.begin(), xs.end(), x) - xs.begin(); rr = lr + 1;
    y1 = y; y2 = y + 1;
    return _get(1, 0, off);
  }
};

struct Rect {
  int x1, x2, y1, y2, z;
};

int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Rect> rs(n);
    map<int, int> ids;

    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &rs[i].x1, &rs[i].x2, &rs[i].y1, &rs[i].y2, &rs[i].z);
      rs[i].x2++, rs[i].y2++;
      ids[rs[i].z] = i;
    }

    int k;
    scanf("%d", &k);
    vector<pt> pts(k);
    for (int i = 0; i < k; i++)
      scanf("%d%d", &pts[i].x, &pts[i].y);

    segm_tree_2d tr(pts);
    for (int i = 0; i < n; i++)
      tr.mod(rs[i].x1, rs[i].x2, rs[i].y1, rs[i].y2, rs[i].z, true);

    for (int i = 0; i < k; i++) {
      int z = tr.get(pts[i].x, pts[i].y);
      int id = -1;
      if (z < INF) {
        id = ids[z];
        tr.mod(rs[id].x1, rs[id].x2, rs[id].y1, rs[id].y2, rs[id].z, false);
      }
      printf("%d\n", id + 1);
    }
    break;
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;

bool cmp2(const pii &a, const pii &b) { return a.second < b.second; }
class quad_tree {
  struct Region {
    int x1, x2, y1, y2;
    Region() : x1(0), x2(-1), y1(0), y2(-1) {}
    Region(int _x1, int _x2, int _y1, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

    bool contains(const Region &r2) const {
      return x1 <= r2.x1 && r2.x2 <= x2 && y1 <= r2.y1 && r2.y2 <= y2;
    }
    bool intersects(const Region &r2) const {
      if (x2 < r2.x1 || r2.x2 < x1) return false;
      if (y2 < r2.y1 || r2.y2 < y1) return false;
      return true;
    }
  };

  typedef struct _node {
    _node *l, *r;
    int val;
    set<int> toadd;
    Region reg;

    _node() : l(0), r(0), val(INF) {}
    _node(vector<pii> &pts) : l(0), r(0), val(INF) {
      assert(sz(pts));

      vi xs, ys;
      for (int i = 0; i < sz(pts); i++)
        xs.pb(pts[i].first),
        ys.pb(pts[i].second);
      sort(xs.begin(), xs.end());
      xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
      sort(ys.begin(), ys.end());
      ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

      reg.x1 = xs[0]; reg.x2 = xs[sz(xs) - 1];
      reg.y1 = ys[0]; reg.y2 = ys[sz(ys) - 1];
      if (sz(xs) == 1 && sz(ys) == 1) return;

      int xm = xs[0], ym = ys[0];

      if (sz(xs) > sz(ys)) {
        xm = xs[(sz(xs) + 1) / 2];
      } else {
        ym = ys[(sz(ys) + 1) / 2];
      }
      vector<pii> ptl;
      int off = 0;
      for (int i = 0; i < sz(pts); i++)
        if (pts[i].first >= xm && pts[i].second >= ym) {
          pts[i - off] = pts[i];
        } else {
          ptl.pb(pts[i]);
          off++;
        }
      pts.resize(sz(pts) - off);

      if (sz(ptl))
        l = new _node(ptl);
      if (sz(pts))
        r = new _node(pts);
    }
    ~_node() {
      if (l) delete l;
      if (r) delete r;
    }

    int getval() { return min(val, toadd.empty() ? INF : *toadd.begin()); }

    void add(const Region &cr, int z, bool _add) {
      if (!cr.intersects(reg)) return;

      if (cr.contains(reg)) {
        if (_add) toadd.insert(z);
        else {
          if (toadd.count(z)) toadd.erase(z);
        }
        return;
      }
      assert(l || r);

      val = INF;
      if (l) l->add(cr, z, _add), val = min(val, l->getval());
      if (r) r->add(cr, z, _add), val = min(val, r->getval());
    }

    int get(const Region &cr) {
      if (!cr.intersects(reg)) return INF;

      int res = INF;
      if (!toadd.empty()) res = min(res, *toadd.begin());

      if (cr.contains(reg)) return min(res, val);
      if (l) res = min(res, l->get(cr));
      if (r) res = min(res, r->get(cr));
      return res;
    }
  } *node;

  node root;

  public:
  quad_tree() : root(0) {}
  quad_tree(const vector<pii> &_pts) {
    vector<pii> pts = _pts;
    root = new _node(pts);
  }
  void add(int x1, int x2, int y1, int y2, int z, bool _add = true) {
    return root->add(Region(x1, x2, y1, y2), z, _add);
  }
  int get(int x, int y) {
    return root->get(Region(x, x, y, y));
  }
};

struct Targ {
  int x1, y1, x2, y2, z;
};
int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Targ> ts(n);
    map<int, int> tzs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &ts[i].x1, &ts[i].x2, &ts[i].y1, &ts[i].y2, &ts[i].z);
      tzs[ts[i].z] = i;
    }

    int m;
    scanf("%d", &m);
    vector<pii> pts(m);
    for (int i = 0; i < m; i++)
      scanf("%d%d", &pts[i].first, &pts[i].second);

    quad_tree tr(pts);
    for (int i = 0; i < n; i++)
      tr.add(ts[i].x1, ts[i].x2, ts[i].y1, ts[i].y2, ts[i].z);

    for (int i = 0; i < m; i++) {
      int cz = tr.get(pts[i].first, pts[i].second);
      if (cz >= INF) {
        printf("0\n");
        continue;
      }
      int id = tzs[cz];
      printf("%d\n", id + 1);
      tr.add(ts[id].x1, ts[id].x2, ts[id].y1, ts[id].y2, ts[id].z, false);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;

bool cmp2(const pii &a, const pii &b) { return a.second < b.second; }
class quad_tree {
  struct Region {
    int x1, x2, y1, y2;
    Region() : x1(0), x2(-1), y1(0), y2(-1) {}
    Region(int _x1, int _x2, int _y1, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

    bool contains(const Region &r2) const {
      return x1 <= r2.x1 && r2.x2 <= x2 && y1 <= r2.y1 && r2.y2 <= y2;
    }
    bool intersects(const Region &r2) const {
      if (x2 < r2.x1 || r2.x2 < x1) return false;
      if (y2 < r2.y1 || r2.y2 < y1) return false;
      return true;
    }
  };

  typedef struct _node {
    _node *l, *r;
    set<int> vals, toadd, todel;
    Region reg;

    _node() : l(0), r(0) {
      vals.insert(INF);
    }
    _node(vector<pii> &pts) : l(0), r(0) {
      assert(sz(pts));
      vals.insert(INF);

      vi xs, ys;
      for (int i = 0; i < sz(pts); i++)
        xs.pb(pts[i].first),
        ys.pb(pts[i].second);
      sort(xs.begin(), xs.end());
      xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
      sort(ys.begin(), ys.end());
      ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

      reg.x1 = xs[0]; reg.x2 = xs[sz(xs) - 1];
      reg.y1 = ys[0]; reg.y2 = ys[sz(ys) - 1];
      if (sz(xs) == 1 && sz(ys) == 1) return;

      int xm = xs[0], ym = ys[0];

      if (sz(xs) > sz(ys)) {
        xm = xs[(sz(xs) + 1) / 2];
      } else {
        ym = ys[(sz(ys) + 1) / 2];
      }
      vector<pii> ptl;
      int off = 0;
      for (int i = 0; i < sz(pts); i++)
        if (pts[i].first >= xm && pts[i].second >= ym) {
          pts[i - off] = pts[i];
        } else {
          ptl.pb(pts[i]);
          off++;
        }
      pts.resize(sz(pts) - off);

      if (sz(ptl))
        l = new _node(ptl);
      if (sz(pts))
        r = new _node(pts);
    }
    ~_node() {
      if (l) delete l;
      if (r) delete r;
    }

    void add(const Region &cr, int z, bool _add) {
      if (!cr.intersects(reg)) return;

      if (cr.contains(reg)) {
        if (_add) toadd.insert(z);
        else {
          if (toadd.count(z)) toadd.erase(z);
          else assert(!vals.count(z));
        }
        return;
      }
      assert(l || r);

      if (l) l->add(cr, z, _add);
      if (r) r->add(cr, z, _add);
      if (_add)
        vals.insert(z);
      else
        vals.erase(z);
    }

    int get(const Region &cr) {
      if (!cr.intersects(reg)) return INF;

      int res = INF;
      if (!toadd.empty()) res = min(res, *toadd.begin());

      if (cr.contains(reg)) return min(res, *vals.begin());
      if (l) res = min(res, l->get(cr));
      if (r) res = min(res, r->get(cr));
      return res;
    }
  } *node;

  node root;

  public:
  quad_tree() : root(0) {}
  quad_tree(const vector<pii> &_pts) {
    vector<pii> pts = _pts;
    root = new _node(pts);
  }
  void add(int x1, int x2, int y1, int y2, int z, bool _add = true) {
    return root->add(Region(x1, x2, y1, y2), z, _add);
  }
  int get(int x, int y) {
    return root->get(Region(x, x, y, y));
  }
};

struct Targ {
  int x1, y1, x2, y2, z;
};
int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Targ> ts(n);
    map<int, int> tzs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &ts[i].x1, &ts[i].x2, &ts[i].y1, &ts[i].y2, &ts[i].z);
      tzs[ts[i].z] = i;
    }

    int m;
    scanf("%d", &m);
    vector<pii> pts(m);
    for (int i = 0; i < m; i++)
      scanf("%d%d", &pts[i].first, &pts[i].second);

    quad_tree tr(pts);
    for (int i = 0; i < n; i++)
      tr.add(ts[i].x1, ts[i].x2, ts[i].y1, ts[i].y2, ts[i].z);

    for (int i = 0; i < m; i++) {
      int cz = tr.get(pts[i].first, pts[i].second);
      if (cz >= INF) {
        printf("0\n");
        continue;
      }
      int id = tzs[cz];
      printf("%d\n", id + 1);
      tr.add(ts[id].x1, ts[id].x2, ts[id].y1, ts[id].y2, ts[id].z, false);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;
class fenv_tree {
  vi tr;
  static int f(int x) { return x ^ (x & (x - 1)); }

  public:
  fenv_tree(int n) : tr(n + 1, -INF) {}
  void relax(int x, int v) {
    for (x++; x > 0; x -= f(x))
      tr[x] = max(tr[x], v);
  }
  int get(int x) {
    int res = -INF;
    for (x++; x < sz(tr); x += f(x))
      res = max(res, tr[x]);
    return res;
  }
};

struct pt {
  int x, y, val;
  bool operator<(const pt &p2) const { return x != p2.x ? x > p2.x : y > p2.y; }
};

int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<pt> pts(n);
    vi ys;
    for (int i = 0; i < n; i++)
      scanf("%d", &pts[i].x);
    for (int i = 0; i < n; i++) {
      scanf("%d", &pts[i].y);
      ys.pb(pts[i].y);
    }
    for (int i = 0; i < n; i++)
      scanf("%d", &pts[i].val);
    sort(ys.begin(), ys.end());
    ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
    for (int i = 0; i < n; i++)
      pts[i].y = lower_bound(ys.begin(), ys.end(), pts[i].y) - ys.begin();

    fenv_tree tr(sz(ys));
    sort(pts.begin(), pts.end());
    int ans = 0;
    for (int st = 0; st < sz(pts);) {
      int en = st;
      while (en < sz(pts) && pts[st].x == pts[en].x) en++;

      for (int i = st; i < en; i++) {
        int mz = tr.get(pts[i].y + 1);
        if (mz > pts[i].val) ans++;
      }
      for (int i = st; i < en; i++)
        tr.relax(pts[i].y, pts[i].val);
      st = en;
    }
    printf("%d\n", ans);
  }
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())

typedef long long ll;

typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int INF = 1e9 + 1000;

bool cmp2(const pii &a, const pii &b) { return a.second < b.second; }
class quad_tree {
  struct Region {
    int x1, x2, y1, y2;
    Region() : x1(0), x2(-1), y1(0), y2(-1) {}
    Region(int _x1, int _x2, int _y1, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

    bool contains(const Region &r2) const {
      return x1 <= r2.x1 && r2.x2 <= x2 && y1 <= r2.y1 && r2.y2 <= y2;
    }
    bool intersects(const Region &r2) const {
      if (x2 < r2.x1 || r2.x2 < x1) return false;
      if (y2 < r2.y1 || r2.y2 < y1) return false;
      return true;
    }
  };

  typedef struct _node {
    _node *l, *r;
    set<int> vals, toadd;
    Region reg;

    _node() : l(0), r(0) {
      vals.insert(INF);
    }
    _node(vector<pii> &pts) : l(0), r(0) {
      assert(sz(pts));
      vals.insert(INF);

      vi xs, ys;
      for (int i = 0; i < sz(pts); i++)
        xs.pb(pts[i].first),
        ys.pb(pts[i].second);
      sort(xs.begin(), xs.end());
      xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
      sort(ys.begin(), ys.end());
      ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

      reg.x1 = xs[0]; reg.x2 = xs[sz(xs) - 1];
      reg.y1 = ys[0]; reg.y2 = ys[sz(ys) - 1];
      if (sz(xs) == 1 && sz(ys) == 1) return;

      int xm = xs[0], ym = ys[0];

      if (sz(xs) > sz(ys)) {
        xm = xs[(sz(xs) + 1) / 2];
      } else {
        ym = ys[(sz(ys) + 1) / 2];
      }
      vector<pii> ptl;
      int off = 0;
      for (int i = 0; i < sz(pts); i++)
        if (pts[i].first >= xm && pts[i].second >= ym) {
          pts[i - off] = pts[i];
        } else {
          ptl.pb(pts[i]);
          off++;
        }
      pts.resize(sz(pts) - off);

      if (sz(ptl))
        l = new _node(ptl);
      if (sz(pts))
        r = new _node(pts);
    }
    ~_node() {
      if (l) delete l;
      if (r) delete r;
    }

    void add(const Region &cr, int z, bool _add) {
      if (!cr.intersects(reg)) return;

      if (cr.contains(reg)) {
        if (_add) toadd.insert(z);
        else {
          if (toadd.count(z)) toadd.erase(z);
          else assert(!vals.count(z));
        }
        return;
      }
      assert(l || r);

      if (l) l->add(cr, z, _add);
      if (r) r->add(cr, z, _add);
      if (_add)
        vals.insert(z);
      else
        vals.erase(z);
    }

    int get(const Region &cr) {
      if (!cr.intersects(reg)) return INF;

      int res = INF;
      if (!toadd.empty()) res = min(res, *toadd.begin());

      if (cr.contains(reg)) return min(res, *vals.begin());
      if (l) res = min(res, l->get(cr));
      if (r) res = min(res, r->get(cr));
      return res;
    }
  } *node;

  node root;

  public:
  quad_tree() : root(0) {}
  quad_tree(const vector<pii> &_pts) {
    vector<pii> pts = _pts;
    root = new _node(pts);
  }
  void add(int x1, int x2, int y1, int y2, int z, bool _add = true) {
    return root->add(Region(x1, x2, y1, y2), z, _add);
  }
  int get(int x, int y) {
    return root->get(Region(x, x, y, y));
  }
};

struct Targ {
  int x1, y1, x2, y2, z;
};
int main() {
  #ifdef DEBUG
  freopen("std.in", "r", stdin);
  freopen("std.out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    vector<Targ> ts(n);
    map<int, int> tzs;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d%d", &ts[i].x1, &ts[i].x2, &ts[i].y1, &ts[i].y2, &ts[i].z);
      tzs[ts[i].z] = i;
    }

    int m;
    scanf("%d", &m);
    vector<pii> pts(m);
    for (int i = 0; i < m; i++)
      scanf("%d%d", &pts[i].first, &pts[i].second);

    quad_tree tr(pts);
    for (int i = 0; i < n; i++)
      tr.add(ts[i].x1, ts[i].x2, ts[i].y1, ts[i].y2, ts[i].z);

    for (int i = 0; i < m; i++) {
      int cz = tr.get(pts[i].first, pts[i].second);
      if (cz >= INF) {
        printf("0\n");
        continue;
      }
      int id = tzs[cz];
      printf("%d\n", id + 1);
      tr.add(ts[id].x1, ts[id].x2, ts[id].y1, ts[id].y2, ts[id].z, false);
    }
  }
  return 0;
}


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

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 19) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    d.w = (d.xl + d.xr + 1) / 2;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    d.w = (d.yl + d.yr + 1) / 2;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.begin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


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

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 3) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    d.w = (d.xl + d.xr + 1) / 2;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    d.w = (d.yl + d.yr + 1) / 2;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.begin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


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

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 9) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    for (int i : d.a)
      p.emplace_back(s[i].x, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    for (int i : d.a)
      p.emplace_back(s[i].y, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.begin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}