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