#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;
int main() {
  ll n, q;
  cin >> n;
  vector<ll> man(100005, 0);
  set<ll> s;
  for (int i = 0; i < (n); ++i) {
    ll a;
    cin >> a;
    man[a]++;
    s.insert(a);
  }
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    ll b, c;
    cin >> b >> c;
    ll tmp = man[b];
    man[b] = 0;
    man[c] += tmp;
    s.erase(b);
    s.insert(c);
    ll result = 0;
    for (auto x : s) {
      result += x * man[x];
    }
    cout << result << endl;
  }
}
