#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  map<long long, long long> kaz;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    kaz[a] += 1;
  }
  int sum = 0;
  for (auto x : kaz) {
    sum += x.first * x.second;
  }
  long long Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    int b = kaz[B];
    kaz[B] = 0;
    kaz[C] += b;
    sum = sum + (C - B) * b;
    cout << sum << endl;
  }
}
