#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, input;
  cin >> n;
  map<int, int> map;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> input;
    sum += input;
    map[input]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int multiplier = map[b];
    map[b] = 0;
    map[c] += multiplier;
    sum = sum - (multiplier * b) + (multiplier * c);
    cout << sum << endl;
  }
  return 0;
}
