#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
using G = vector<map<int, int>>;
int main() {
  int N;
  cin >> N;
  vector<ll> num(10);
  ll acum = 0;
  for (ll i = (0); (i) < (N); i++) {
    ll tmp;
    cin >> tmp;
    num[tmp]++;
    acum += tmp;
  }
  int Q;
  cin >> Q;
  vector<pair<int, int>> q(Q);
  for (ll i = (0); (i) < (Q); i++) cin >> q[i].first >> q[i].second;
  for (ll i = (0); (i) < (Q); i++) {
    int B = q[i].first;
    int C = q[i].second;
    num[C] += num[B];
    acum = acum + (num[B] * (C - B));
    num[B] = 0;
    cout << acum << endl;
  }
}
