#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> mp;
  ll s = 0;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    s += a;
    mp[a]++;
  }
  int q;
  cin >> q;
  vector<int> B(q), C(q);
  for (int i = 0; i < (q); ++i) cin >> B[i] >> C[i];
  for (int i = 0; i < (q); ++i) {
    int b = B[i], c = C[i];
    int tmp = mp[b];
    mp[b] = 0;
    mp[c] += tmp;
    s -= b * tmp;
    s += c * tmp;
    cout << s << endl;
  }
  return 0;
}
