#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, a, b, m;
map<int, int> mp;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    mp[a]++;
  }
  long long sum = 0;
  for (int i = 1; i <= 100000; i++) {
    if (mp[i]) {
      sum += i * mp[i];
    }
  }
  cin >> m;
  while (m-- > 0) {
    cin >> a >> b;
    sum -= mp[a] * a;
    sum += mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
