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