#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  map<int, int> mp2;
  int arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i], mp[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int var = mp[b];
    mp[b] = 0;
    sum -= (var * b);
    sum += (c * var);
    if (mp[c] != 0) {
      int atr = mp[c];
      atr += (var);
      mp[c] = atr;
    } else {
      mp[c] += var;
    }
    cout << sum << "\n";
  }
  return 0;
}
