#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;
int main() {
  int N, Q, t, b, c;
  vector<int> map(1e5, 0);
  cin >> N;
  ll sum = 0;
  for (int i = 0; i < (N); ++i) {
    cin >> t;
    sum += t;
    map[t] += 1;
  }
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    cin >> b >> c;
    if (map[b] != 0) {
      map[c] += map[b];
      sum = (c - b) * map[b];
      map[b] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
