#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ara[n + 1], sum = 0;
  map<long long int, long long int> make_pair;
  for (long long int i = 0; i < n; i++) {
    cin >> ara[i];
    make_pair[ara[i]]++;
    sum += ara[i];
  }
  long long int m;
  cin >> m;
  while (m--) {
    long long int a, b;
    cin >> a >> b;
    sum -= (make_pair[a] * a);
    sum += (make_pair[a] * b);
    make_pair[b] += make_pair[a];
    cout << sum << endl;
  }
}
