#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long arr[n], sum = 0;
  int ar[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    ar[arr[i]]++;
  }
  int q;
  cin >> q;
  long long b, c;
  while (q--) {
    cin >> b >> c;
    if (ar[b] == 0) {
      cout << sum << '\n';
      continue;
    }
    int val = ar[b];
    int total = val * b;
    sum -= total;
    ar[b] = 0;
    ar[c] += val;
    sum += (c * val);
    cout << sum << '\n';
  }
}
