#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(100050, 0);
  for (int i = 0; i < (n); i++) {
    int p;
    cin >> p;
    v[p]++;
  }
  int q;
  cin >> q;
  int b, c;
  long long ans = 0;
  int diff;
  for (int i = 0; i < (10050); i++) {
    ans += v[i] * i;
  }
  for (int i = 0; i < (q); i++) {
    cin >> b >> c;
    diff = c - b;
    ans += v[b] * diff;
    v[c] += v[b];
    v[b] = 0;
    cout << ans << endl;
  }
}
