Curious Cupid

There are $K$ different languages in the world. Each person speaks one and only one language. There are exactly $N$ single men and $N$ single women.

Cupid, the god of love, wants to match every single man to a single woman, and vice versa. Everybody wants to find a partner who speaks the same language as s/he does. Communication between the couple is very important! Cupid asks these $N$ men to stand in a line, and likewise for the $N$ women. Cupid knows that the $i$th man speaks language $a_ i$ and the $i$th woman speaks language $b_ i$.

It is too hard for Cupid to match all people at the same time. What Cupid does is to repeatedly look at some specific interval in these two lines, pick the men and women in that interval and find the maximum number of man-woman pairs who speak the same language and can be matched.


  • The first line contains three integers $N$, $M$ and $K$ $(1 \leq N \leq 50\, 000, 1 \leq M \leq 50\, 000, 1 \leq K \leq 1\, 000\, 000)$.

  • The second line contains $N$ integers $a_0, a_1, a_2, \dots , a_{N-1}$, where $a_ i$ ($0 \leq a_ i < K$) is the language spoken by the $i$th man.

  • The third line contains $N$ integers $b_0, b_1, b_2, \dots , b_{N-1}$, where $b_ i$ ($0 \leq b_ i < K$) is the language spoken by the $i$th woman.

  • In the next $M$ lines, each line contains two integers $L$ and $R$ ($0 \leq L \leq R < N$), representing the starting and ending index of the interval. That is, Cupid is looking at men $L, L+1, \dots , R$ and women $L, L+1, \dots , R$.


For each interval, print the maximum number of couples Cupid could match.

Sample Input 1 Sample Output 1
3 4 2
0 0 1
0 0 0
0 0
2 2
0 1
1 2