#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  unordered_map<int, int> mp;
  int count = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    mp[arr[i]]++;
    count += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (mp[b]) {
      count -= b * mp[b];
      count += mp[b] * c;
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << count << "\n";
  }
}
