#include <bits/stdc++.h>
using namespace std;
int N;
int A[100001];
int Q;
int B[100001];
int C[100001];
int acc[100001] = {0};
int S = 0;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    acc[A[i]]++;
    S += A[i];
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d%d", &B[i], &C[i]);
    int t = acc[B[i]];
    acc[B[i]] = 0;
    acc[C[i]] += t;
    S += t * (C[i] - B[i]);
    printf("%d\n", S);
  }
  return 0;
}
