#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  map<int, int> mp;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  vector<ll> s(q + 1);
  s[0] = sum;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    if (!mp.count(b)) {
      s[i] = s[i - 1];
      continue;
    }
    s[i] = s[i - 1] + (c - b) * mp.at(b);
    mp[c] += mp.at(b);
    mp.erase(b);
  }
  for (int i = 1; i <= q; i++) cout << s[i] << endl;
  return 0;
}
