#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  vector<int> a_num;
  for (int i = 0; i < (n); ++i) {
    int co = count(a.begin(), a.end(), i + 1);
    a_num.push_back(co);
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    sum += a_num[b - 1] * (c - b);
    cout << sum << endl;
    a_num[c - 1] += a_num[b - 1];
    a_num[b - 1] = 0;
  }
  return 0;
}
