#include <bits/stdc++.h>
using namespace std;
const int N = 1 * 1e5 + 5;
const long long mod = 1e9 + 7;
const double E = 1e-9;
long long fre[N];
long long BIT[N];
int n;
void update(int pos, int val) {
  for (int i = pos; i < N; i += i & (-i)) BIT[i] += val;
}
void build() {
  for (int i = 1; i < N; i++) update(i, 1ll * fre[i] * i);
}
long long getSum() {
  long long sum = 0;
  for (int i = N - 1; i >= 1; i -= i & (-i)) sum += BIT[i];
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i += 1) {
    int x;
    cin >> x;
    fre[x]++;
  }
  int q;
  cin >> q;
  build();
  cerr << "getSum()"
       << " is " << getSum() << '\n';
  while (q--) {
    long long B, C;
    cin >> B >> C;
    update(B, -fre[B] * B);
    update(C, fre[B] * C);
    fre[C] += fre[B];
    fre[B] = 0;
    cout << getSum() << '\n';
  }
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
