#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  int sum = 0;
  map<int, int> m;
  for (auto v : a) {
    m[v]++;
    sum += v;
  }
  for (int i = 0; i < (q); ++i) {
    int bi = b[i];
    int ci = c[i];
    int bi_cnt = m[bi];
    m[bi] = 0;
    m[ci] += bi_cnt;
    sum = sum - bi * bi_cnt + ci * bi_cnt;
    cout << sum << endl;
  }
  return 0;
}
