#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  map<ll, int> cnt;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= cnt[b] * b;
    sum += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
