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