#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  long long ans = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    ans += arr[i];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    if (mp[b] == 0) {
      cout << ans << endl;
      continue;
    }
    ans -= mp[b] * b;
    ans += mp[b] * c;
    mp[c] += mp[b];
    mp[b] = 0;
    cout << ans << endl;
  }
}
