#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int tmp;
  ll sum = 0;
  for (long long i = 0; i < (n); ++i) {
    cin >> tmp;
    sum += tmp;
    auto itr = mp.find(tmp);
    if (itr != mp.end()) {
      mp[tmp]++;
    } else {
      mp[tmp] = 1;
    }
  }
  int Q;
  cin >> Q;
  int b, c;
  for (long long i = 0; i < (Q); ++i) {
    cin >> b >> c;
    int count_b = mp[b];
    sum = sum + count_b * c - count_b * b;
    auto itr = mp.find(c);
    if (itr != mp.end()) {
      mp[c] += mp[b];
      mp[b] = 0;
    } else {
      mp[c] = mp[b];
      mp[b] = 0;
    }
    cout << (sum) << endl;
    ;
  }
  return 0;
}
