#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  map<ll, ll> mp;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    mp[A[i]]++;
  }
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &B[i]);
    scanf("%lld", &C[i]);
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    ll sum = 0;
    for (auto &e : mp) sum += e.first * e.second;
    cout << sum << endl;
  }
  return 0;
}
