#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(100000, 0);
  for (int i = 0; i < (int)(N); i++) {
    int a;
    cin >> a;
    A.at(a - 1)++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    int b, c;
    cin >> b >> c;
    int tmp = A.at(b - 1);
    A.at(b - 1) = 0;
    A.at(c - 1) += tmp;
    long long total = 0;
    for (int j = 0; j < (int)(100000); j++) {
      total += (j + 1) * A.at(j);
    }
    cout << total << endl;
  }
}
