#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[10005], q, b[10005], c[10005], d[10005], e[10005], sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[a[i]]++;
    sum += a[i];
  }
  e[0] = sum;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 1; i <= q; i++) {
    e[i] = d[b[i]] * (c[i] - b[i]) + e[i - 1];
    d[c[i]] = d[c[i]] + d[b[i]];
  }
  for (int i = 1; i <= q; i++) {
    cout << e[i] << endl;
  }
}
