#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  long sum = 0;
  for (int i = 0; i < N; i++) sum += A[i];
  map<int, int> C;
  for (int a = 1; a <= 100000; a++) C[a] = 0;
  for (int i = 0; i < N; i++) C[A[i]]++;
  int Q;
  cin >> Q;
  int b, c;
  for (int q = 0; q < Q; q++) {
    cin >> b >> c;
    int dif_num = C[b];
    C[c] += C[b];
    sum += dif_num * (long)(c - b);
    cout << sum << endl;
  }
}
