#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long A[N];
  map<long long, long long> map;
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> A[i];
    map[A[i] - 1]++;
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (long long)(Q); i++) {
    long long B, C;
    cin >> B >> C;
    map[C - 1] += map[B - 1];
    map.erase(B - 1);
    long long sum = 0;
    for (auto m : map) {
      sum += m.second * (m.first + 1);
    }
  }
}
