#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[N];
  int tab[100000];
  for (int i = 1; i < 100001; i++) {
    tab[i] = 0;
  }
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
    tab[a[i]]++;
  }
  int Q;
  cin >> Q;
  int b[Q], c[Q];
  for (int i = 0; i < Q; i++) {
    cin >> b[i] >> c[i];
  }
  long long change = 0;
  for (int i = 0; i < Q; i++) {
    if (tab[b[i]] > 0) {
      tab[c[i]] += tab[b[i]];
      change = tab[b[i]] * (c[i] - b[i]);
      tab[b[i]] = 0;
    }
    sum = sum + change;
    cout << sum << endl;
    change = 0;
  }
}
