#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c, af;
  int sum = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> num(100000);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a.at(i);
    af = a.at(i);
    sum += a.at(i);
    num.at(af - 1) = num.at(af - 1) + 1;
  }
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    cin >> b >> c;
    sum = sum + (c - b) * num.at(b - 1);
    cout << sum << endl;
    num.at(c - 1) += num.at(b - 1);
    num.at(b - 1) = 0;
  }
}
