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