#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const int m = 100003;
ll to[m];
int main() {
  ll n, s = 0;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    to[x]++;
    s += x;
  }
  ll q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    ll b, c;
    cin >> b >> c;
    s -= b * to[b];
    s -= c * to[c];
    to[c] += to[b];
    s += c * to[c];
    cout << s << endl;
  }
  return 0;
}
