#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}" << endl;
  return o;
}
long long mpow(long long n, long long t) {
  for (int i = 0; i < t; i++) n *= n;
  if (t == 0) n = 1;
  return n;
}
int main() {
  int N, Q, a, b, c;
  cin >> N;
  map<int, int> A;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A[a]++;
  }
  long long ans = 0;
  for (auto itr = A.begin(); itr != A.end(); itr++) {
    ans += itr->first * itr->second;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    ans += c * A[b];
    ans -= b * A[b];
    A[c] += A[b];
    A[b] = 0;
    cout << ans << endl;
  }
}
