#include <bits/stdc++.h>
using namespace std;
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0, i_len = ((int)(v).size()); i < i_len; ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
inline ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
const long long int LINF = (long long int)9e18 + 7;
const int INF = 100100100;
const long long int MOD = 1e9 + 7;
int main() {
  int N;
  cin >> N;
  vector<int> A(100010, 0);
  long long int cnt = 0;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int t;
    cin >> t;
    A[t]++;
    cnt += t;
  }
  int Q;
  cin >> Q;
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    int B, C;
    cin >> B >> C;
    cnt -= B * A[B];
    cnt += C * A[B];
    A[C] += A[B];
    A[B] = 0;
    cout << cnt << endl;
  }
  return 0;
}
