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