#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int n;
  cin >> n;
  long long int an[(100001)];
  long long int sum = 0;
  for (long long int i = 0; i < n; ++i) {
    long long int a;
    cin >> a;
    ++an[a];
    sum += a;
  }
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; ++i) {
    long long int b, c;
    cin >> b >> c;
    sum += (c - b) * an[b];
    an[c] += an[b];
    an[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
