#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t, y;
    cin >> t >> y;
    sum += ((y - t) * a[t]);
    cout << sum << endl;
    a[y] += a[t];
    a[t] = 0;
  }
  return 0;
}
