#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<string>;
Graph field;
queue<P> q;
int main() {
  ll n, sum;
  sum = 0;
  cin >> n;
  ll a[100001];
  for (int i = 0; i < (n); ++i) {
    ll ab;
    cin >> ab;
    a[ab]++;
    sum += ab;
  }
  ll q;
  queue<ll> que;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    ll b, c;
    cin >> b >> c;
    a[c] += a[b];
    sum += (c - b) * a[b];
    a[b] = 0;
    que.push(sum);
  }
  while (!que.empty()) {
    cout << que.front() << endl;
    que.pop();
  }
}
