#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x;
  long long int sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (mp.find(a) != mp.end()) {
      sum = sum - (mp[a] * a);
      sum = sum + (mp[a] * b);
      int l = mp[a];
      mp.erase(a);
      if (mp.find(b) != mp.end()) {
        mp[b] = mp[b] + l;
      } else {
        mp[b] = l;
      }
    }
    cout << sum << "\n";
  }
}
