#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(n + 1, 0);
  for (int i = 0; i < (n); ++i) {
    a_num[a[i]]++;
  }
  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] * (c - b);
    cout << sum << endl;
    a_num[c] += a_num[b];
    a_num[b] = 0;
  }
  return 0;
}
