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