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