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