#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, Q;
  vector<long long int> a_v, b_v, c_v;
  map<int, int> num_m;
  cin >> N;
  for (int i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    a_v.push_back(a);
    num_m[a]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long int B, C;
    cin >> B >> C;
    b_v.push_back(B);
    c_v.push_back(C);
  }
  auto num_m_tmp = num_m;
  for (long long int i = 0; i < Q; i++) {
    num_m_tmp[c_v[i]] += num_m_tmp[b_v[i]];
    num_m_tmp[b_v[i]] = 0;
    long long int sum = 0;
    for (auto itr = num_m_tmp.begin(); itr != num_m_tmp.end(); ++itr) {
    }
    for (auto itr = num_m_tmp.begin(); itr != num_m_tmp.end(); ++itr) {
      sum += itr->first * itr->second;
    }
    cout << sum << endl;
  }
  return 0;
}
