#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q, sum = 0, b, k, count[10000] = {0};
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    count[a[i] - 0]++;
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> b >> q;
    sum = sum + count[b] * (q - b);
    count[q] = count[q] + count[b];
    count[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
