#include <bits/stdc++.h>
const int MOD{int(1e9 + 7)};
const int inf{2100000000};
using namespace std;
void printVec(vector<int>& vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
  cout << endl;
}
int sumVec(vector<int> v) {
  int sum = 0;
  for (size_t i = 0; i < v.size(); i++) sum += v[i];
  return sum;
}
int main(void) {
  long long ck[100010] = {0};
  long long sum = 0;
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    ck[A[i]]++;
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q), C(Q), S(Q);
  for (long long i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    if (ck[B[i]] != 0) {
      S[i] = sum + (C[i] - B[i]) * ck[B[i]];
      ck[C[i]] += ck[B[i]];
      ck[B[i]] = 0;
    } else {
      S[i] = S[i - 1];
    }
    sum = S[i];
  }
  for (long long i = 0; i < Q; i++) cout << S[i] << endl;
  return 0;
}
