#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long sum = 0, cou[100005] = {0};
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    cou[x]++;
    sum = sum + x;
  }
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    sum = sum - cou[b] * b + cou[b] * c;
    cou[c] += cou[b];
    cout << sum << endl;
  }
  return 0;
}
