#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int MAX = 10005;
int counter[MAX];
int main() {
  int n;
  cin >> n;
  long long a[n];
  long long fsum = 0;
  for (int i = 0; i < MAX; ++i) {
    counter[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    counter[a[i]]++;
    fsum += a[i];
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    long long cur = counter[b[i]];
    counter[b[i]] = 0;
    counter[c[i]] += cur;
    fsum += (long long)((c[i] - b[i]) * cur);
    cout << fsum << endl;
  }
  return 0;
}
