#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const double pi = acos(-1);
template <class t, class u>
inline bool chmax(t& a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
inline bool chmin(t& a, u b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
istream& operator>>(istream& is, vector<T>& a) {
  for (int i = 0; i < (int)(a.size()); ++i) is >> a[i];
  return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& a) {
  for (int i = 0; i < (int)(a.size()); ++i) os << a[i] << " ";
  return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
  for (auto& t : mp) os << t.first << " " << t.second << "\n";
  return os;
}
int main() {
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  ll sum = accumulate((a).begin(), (a).end(), 0);
  map<int, int> mp;
  for (int i = 0; i < (int)(n); ++i) {
    mp[a[i]]++;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * mp[b];
    cout << sum << "\n";
    mp[c] += mp[b];
    mp[b] = 0;
  }
}
