#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int IINF = 1000000000;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < (Q); i++) cin >> B[i] >> C[i];
  map<int, long long> counter;
  for (int i = 0; i < (N); i++) {
    counter[A[i]]++;
  }
  for (int i = 0; i < (Q); i++) {
    long long b_count = counter[B[i]];
    counter[B[i]] = 0;
    counter[C[i]] += b_count;
    long long ans = 0;
    for (auto c : counter) {
      ans += (c.first * c.second);
    }
    cout << ans << endl;
  }
}
