logo AlgoBeat OnlineJudge
登录 注册

#217298. [ICPC 2017 Xi'an R] LOVER II

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

One day girls and boys come to Xi'an to look for a mate. Each girl has a value , each boy has a value . Girl and boy will fall in love only if .

Then queries follow. Ask you to calculate if we only have boys labeled from to , can we make all girls find their lovers?

输入格式

Several test cases (no more than ).

First line an integer . Indicates the number of test cases.

Then test cases follow. Each test case begins with three integers . The next line has integers indicating to . The next line has integers indicating to .

Then comes an integer . .

The next lines each contain two integers indicating each query.

输出格式

For each query, print "1" if we can make it or "0" otherwise.

样例

样例输入 1

1
3 4 5
1 1 1
4 4 4 3
2
1 3
2 4

样例输出 1

1
0