#include <bits/stdc++.h>
const int INF = 1111111111;
const double EPS = 1e-9;
using namespace std;
const int N = 111111;
int n;
int a[N];
int q;
int b[N], c[N];
void init() {
  cin >> n;
  for (int i = (0); i < (int)(n); i++) cin >> a[i];
  cin >> q;
  for (int i = (0); i < (int)(q); i++) cin >> b[i] >> c[i];
}
int memo[N];
void solve() {
  for (int i = (0); i < (int)(n); i++) {
    memo[a[i]]++;
  }
  int sum = 0;
  for (int i = (0); i < (int)(N); i++) {
    sum += i * memo[i];
  }
  for (int i = (0); i < (int)(q); i++) {
    int minus = b[i] * memo[b[i]];
    int plus = c[i] * memo[b[i]];
    memo[c[i]] += memo[b[i]];
    memo[b[i]] = 0;
    sum += plus - minus;
    cout << sum << endl;
  }
}
int main() {
  init();
  solve();
}
