#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(1e5 + 1);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++vec[a];
  }
  int q;
  cin >> q;
  long long vsum = 0;
  for (int j = 1; j <= 1e5 + 1; ++j) vsum += j * vec[j];
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    vsum -= vec[b] * b;
    vsum += vec[b] * c;
    vec[c] += vec[b];
    vec[b] = 0;
    cout << vsum << endl;
  }
}
