#include <bits/stdc++.h>
using namespace std;
int main() {
  int f[100001] = {0};
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    f[temp]++;
  }
  unsigned long long sum = 0;
  for (int i = 0; i < 100001; i++) {
    sum += (i * f[i]);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int freq = f[b];
    f[b] = 0;
    f[c] += freq;
    sum = sum - freq * b + freq * c;
    cout << sum << '\n';
  }
  return 0;
}
