#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int arr[n];
  map<int, int> s;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    s[arr[i]]++;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += arr[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (s[b] != 0) {
      int dif = b * s[b];
      int add = c * s[b];
      s[c] += s[b];
      s[b] = 0;
      sum -= dif;
      sum += add;
    }
    cout << sum << "\n";
  }
}
