#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
  int n, q, b, c;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> q;
    b = 1;
    for (size_t j = 0; j < a.size(); j += 2)
      if (a[j] == q) {
        a[j + 1] += 1;
        b = 0;
      }
    if (b) {
      a.push_back(q);
      a.push_back(1);
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    for (size_t j = 0; j < a.size(); j += 2)
      if (a[j] == b) a[j] = c;
    b = 0;
    for (size_t j = 0; j < a.size(); j += 2) b += a[j] * a[j + 1];
    cout << b << endl;
  }
}
