#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> As(100010, 0);
  for (long long i = 0; i < (long long)(N); i++) {
    long long A;
    cin >> A;
    As[A]++;
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (long long)(Q); i++) {
    long long B;
    cin >> B;
    long long C;
    cin >> C;
    long long keep;
    keep = As[B];
    As[B] = 0;
    As[C] += keep;
    long long ans = 0;
    for (long long i = 0; i < (long long)(100010); i++) {
      ans += i * As[i];
    }
    cout << ans;
    cout << endl;
  }
}
