#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1000000000;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> counter;
  int current_sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    current_sum += A[i];
    counter[A[i]]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int bi, ci;
    cin >> bi >> ci;
    current_sum -= bi * counter[bi];
    current_sum += ci * counter[bi];
    counter[ci] += counter[bi];
    counter[bi] = 0;
    cout << current_sum << endl;
  }
}
