#include <bits/stdc++.h>
using namespace std;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  unordered_map<int32_t, int32_t> map;
  int32_t N;
  cin >> N;
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    map[A]++;
    sum += A;
  }
  int32_t Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int32_t b, c;
    cin >> b >> c;
    int32_t bcnt = map[b];
    sum -= bcnt * b;
    map[b] = 0;
    sum += bcnt * c;
    map[c] += bcnt;
    cout << sum << endl;
  }
  return 0;
}
