#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, sum = 0;
  cin >> n;
  int count[100001] = {0};
  for (int i = 1; i <= n; i++) {
    int l;
    cin >> l;
    count[l]++;
    sum += l;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * count[b];
    sum += c * count[b];
    count[c] += count[b];
    count[b] = 0;
    cout << sum << endl;
  }
}
