Sona, Maven of the Strings. Of cause, she can play the zither.
Sona can't speak but she can make fancy music. Her music can attack, heal, encourage and enchant.
There're an ancient score(乐谱). But because it's too long, Sona can't play it in a short moment. So Sona decide to just play a part of it and revise it.
A score is composed of notes. There are 109 kinds of notes and a score has 105 notes at most.
To diversify Sona's own score, she have to select several parts of it. The energy of each part is calculated like that:
Count the number of times that each notes appear. Sum each of the number of times' cube together. And the sum is the energy.
You should help Sona to calculate out the energy of each part.
This problem contains several cases. And this problem provides 2 seconds to run.
The first line of each case is an integer N (1 ≤ N ≤ 10^5), indicates the number of notes.
Then N numbers followed. Each number is a kind of note. (1 ≤ NOTE ≤ 10^9)
Next line is an integer Q (1 ≤ Q ≤ 10^5), indicates the number of parts.
Next Q parts followed. Each part contains 2 integers Li and Ri, indicates the left side of the part and the right side of the part.
For each part, you should output the energy of that part.
1 1 3 1 3 1 3 3