#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<long long>;
using P = pair<long long, long long>;
using T = tuple<long long, long long, long long>;
using ll = long long;
long long charToInt(char c) {
  char zero_num = '0';
  return (long long)c - (long long)zero_num;
}
signed main() {
  long long N;
  cin >> N;
  vec_int A(N);
  for (long long i = 0; i < (long long)(N); i++) cin >> A.at(i);
  long long Q;
  cin >> Q;
  vec_int B(Q), C(Q);
  for (long long i = 0; i < (long long)(Q); i++) cin >> B.at(i) >> C.at(i);
  map<long long, long long> int_map;
  long long init_val = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    if (int_map.count(A.at(i)) == 0) {
      int_map[A.at(i)] = 1;
    } else {
      int_map[A.at(i)]++;
    }
    init_val += A.at(i);
  }
  for (long long i = 0; i < (long long)(Q); i++) {
    long long temp = int_map[B.at(i)];
    int_map[B.at(i)] = 0;
    if (int_map.count(C.at(i)) == 0) {
      int_map[C.at(i)] = temp;
    } else {
      int_map[C.at(i)] += temp;
    }
    init_val -= temp * B.at(i);
    init_val += temp * C.at(i);
    cout << init_val << endl;
  }
  return 0;
}
