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