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