#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> V(100001, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    V[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int d = c - b;
    V[c] += V[b];
    sum += d * V[b];
    V[b] = 0;
    cout << sum << endl;
  }
}
