Heroes and Monsters
There are heroes and monsters. The heroes and monsters are numbered with integers from to . The strength of the -th hero is equal to , and the strength of the -th monster is equal to . It is guaranteed that all values are pairwise distinct.
There will be a total of battles. In each battle, exactly one hero and exactly one monster will participate, with each hero and each monster participating in exactly one battle. Let the battle involve the hero with number and the monster with number . If , then the hero with number will be happy, otherwise, he will be sad.
Let be the number of different sets of heroes of size , such that there is a distribution of battles where all heroes in will be happy and all other heroes will be sad.
Given queries of the form , . For each query, find .
Input
The first line contains a single integer () — the number of battles that will take place.
The second line contains integers () — the strengths of the heroes.
The third line contains integers — the strengths of the monsters.
It is guaranteed that all values are pairwise distinct.
The fourth line contains a single integer — the number of queries.
The next lines contain two integers each, and — the parameters of the corresponding query.
It is guaranteed that all values are pairwise distinct.
Output
For each query, output a single integer — the required value .
Examples
Note
The image below shows the heroes and monsters of the first example. The heroes are at the top, and the monsters are at the bottom. The number inside the square represents the strength of the corresponding hero or monster.
In the example, there are three possible sets of happy heroes: , , and . Below are three possible distributions of battles in which the corresponding sets of heroes will be happy. Note that there may be multiple distributions of battles where the same set of heroes will be happy.
Scoring
( points): for ;
( points): , , ;
( points): , for ;
( points): , , , ;
( points): , , ;
( points): , ;
( points): ;
( points): without additional restrictions.