#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 10010001010;
const int inf = 1000034000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  long long N;
  cin >> N;
  long long sum = 0;
  vector<int> A(N);
  map<int, int> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    M[A[i]]++;
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    sum -= M[B] * B;
    sum += M[B] * C;
    M[C] += M[B];
    M[B] = 0;
    cout << sum << endl;
  }
}
