#include <bits/stdc++.h>
using namespace std;
bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
  return arg1.first > arg2.first;
}
template <class T>
void chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
void chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
}
int main(void) {
  int n;
  cin >> n;
  vector<int> a(100005);
  int atmp, ans = 0;
  for (int in = 0; in < n; in++) {
    cin >> atmp;
    atmp--;
    a.at(atmp)++;
    ans += atmp + 1;
  }
  int b, c, q;
  cin >> q;
  for (int iq = 0; iq < q; iq++) {
    cin >> b >> c;
    b--;
    c--;
    ans += (c - b) * a.at(b);
    a.at(c) += a.at(b);
    a.at(b) = 0;
    cout << ans << endl;
  }
  return 0;
}
