#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int sum = 0;
  vector<int> A;
  int V[100000] = {};
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    A.push_back(temp);
    V[temp] += 1;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    int diff = C - B;
    sum += V[B] * diff;
    int x = V[B];
    V[B] = 0;
    V[C] += x;
    cout << sum << endl;
  }
}
