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