#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5;
vector<int> bit(nax + 1), cnt(nax);
int get_sum(int i) {
  int sum = 0;
  while (i >= 0) {
    sum += bit[i];
    i = (i & (i + 1)) - 1;
  }
  return sum;
}
void upd(int j, int x) {
  while (j < nax) {
    bit[j] += x;
    j = j | (j + 1);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    upd(a[i], a[i]);
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int del = x * cnt[x];
    upd(x, -del);
    upd(y, y * cnt[x]);
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << get_sum(nax) << endl;
    ;
  }
}
