#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  unordered_map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    sum += v[i];
    mp[v[i]]++;
  }
  int Q, B, C;
  cin >> Q;
  while (Q--) {
    cin >> B >> C;
    int t = mp[B];
    mp.erase(B);
    if (mp.find(C) != mp.end())
      mp[C] += t;
    else
      mp[C] = t;
    sum = sum + (C - B) * t;
    cout << sum << "\n";
  }
}
