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