#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  os << '[';
  for (int i = 0; i < (int)V.size(); i++)
    os << V[i] << ",]"[i == (int)V.size() - 1];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (T &x : V) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << '{' << p.first << ',' << p.second << '}';
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
int const MAXN = 100100;
int cnt[MAXN];
int solve() {
  int n;
  long long sum = 0LL;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    cnt[tmp]++;
    sum += tmp;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    cnt[b] += cnt[a];
    sum -= cnt[a] * a;
    sum += cnt[a] * b;
    cnt[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
int main() {
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  int T = 1;
  while (T--) {
    solve();
  }
}
