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