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