#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int M = 100010;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(M);
  ll sum = 0;
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.at(i) = a;
    sum += a;
    cnt.at(a)++;
  }
  int Q;
  cin >> Q;
  int b, c;
  int d;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    d = cnt.at(b);
    cnt.at(b) = 0;
    cnt.at(c) += d;
    sum -= d * b;
    sum += d * c;
    cout << sum << endl;
  }
}
