#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  long long int sum = 0;
  long long int freq[100000];
  memset(freq, 0, sizeof(freq));
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    freq[a[i]]++;
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    sum -= freq[x] * x;
    sum += freq[x] * y;
    freq[y] += freq[x];
    freq[x] = 0;
    cout << sum << "\n";
  }
  return 0;
}
