#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, temp;
  long long int sum(0);
  cin >> n;
  vector<int> num;
  num.assign(100001, 0);
  for (int i = 0; i < n; i++) {
    cin >> temp;
    num[temp]++;
    sum += temp;
  }
  int q, bb, cc;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> bb >> cc;
    sum -= num[bb] * bb;
    sum += num[bb] * cc;
    num[cc] += num[bb];
    num[bb] = 0;
    cout << sum << endl;
  }
  return 0;
}
