#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N;
  long long total = 0, val;
  cin >> N;
  vector<int> A(100001, 0);
  for (int i = 0; i < N; ++i) {
    cin >> val;
    ++A[val];
    total += val;
  }
  int Q, B, C, amount;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> B >> C;
    amount = A[B];
    A[B] = 0;
    total -= amount * B;
    A[C] += amount;
    total += amount * C;
    cout << total << '\n';
  }
}
