#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const int INFTY = (1 << 30);
int N, Q;
void func() {
  cin >> N;
  int A, table[100001] = {}, ans(0);
  for (int i = (int)(0); i < (int)(N); ++i) {
    cin >> A;
    ++table[A];
    ans += A;
  }
  cin >> Q;
  int B, C;
  for (int i = (int)(0); i < (int)(Q); ++i) {
    cin >> B >> C;
    table[C] += table[B];
    ans += (C - B) * table[B];
    table[B] = 0;
    cout << ans << endl;
  }
}
int main() { func(); }
