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