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