#include <bits/stdc++.h>
using namespace std;
int n, q, a, b, c;
unsigned long long s = 0, sum = 0;
int main() {
  vector<int> v(100005);
  cin >> n;
  int m = 1000000, x = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    v[a]++;
  }
  for (int i = 1; i <= 100004; ++i) sum += i * v[i];
  s = sum;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    v[c] += v[b];
    s += v[b] * c;
    s -= v[b] * b;
    v[b] = 0;
    cout << s << "\n";
  }
}
