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