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