#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)998244353;
const ll INF = (ll)1e18 + 10;
const double PI = 2.0 * acos(0);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};
void solve(int ca) {
  int N;
  cin >> N;
  int cnt[100010];
  ll ans = 0ll;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    cnt[a]++;
    ans += (ll)a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int b, c;
    cin >> b >> c;
    ans += (ll)cnt[b] * (c - b);
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << ans << endl;
  }
}
int main() {
  solve(0);
  return 0;
}
