#include <bits/stdc++.h>
using namespace std;
int main() {
  unordered_map<int, int> mp;
  int n, q, a, b, k;
  cin >> n;
  int i;
  long long int sum = 0;
  for (i = 0; i < n; i++) {
    cin >> k;
    sum += k;
    mp[k]++;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    k = mp[a];
    sum -= k * a;
    mp[a] = 0;
    mp[b] = mp[b] + k;
    sum += k * b;
    cout << sum << "\n";
  }
  return 0;
}
