#include <bits/stdc++.h>
using namespace std;
long long prime[1000001];
long long mod;
long long rec(vector<vector<long long> >& dp, vector<long long>& arr, int n,
              int i, int k, int w) {
  long long ans = 0;
  if (i >= n) return 0;
  if (dp[i][k] != -1) return dp[i][k];
  if (k != 0)
    ans = max(rec(dp, arr, n, i + 1, w, w),
              arr[i] + rec(dp, arr, n, i + 1, k - 1, w));
  else
    ans = max(rec(dp, arr, n, i + 1, k, w), rec(dp, arr, n, i + 1, w, w));
  return dp[i][k] = ans;
}
long long t[400008];
void build(vector<long long>& a, int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = a[tl];
  } else {
    int tm = (tl + tr) / 2;
    build(a, v * 2, tl, tm);
    build(a, v * 2 + 1, tm + 1, tr);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
long long maxi(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) {
    return t[v];
  }
  int tm = (tl + tr) / 2;
  return max(maxi(v * 2, tl, tm, l, min(r, tm)),
             maxi(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int pos, long long new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, new_val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  unordered_map<int, int> h;
  int t;
  for (int i = 0; i < n; i++) {
    cin >> t;
    h[t]++;
    ans += t;
  }
  int q;
  cin >> q;
  int a, b;
  long long temp;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    h[b] += h[a];
    ans = ans - h[a] * a + h[a] * b;
    h[a] = 0;
    cout << ans << "\n";
  }
  return 0;
}
