#include <bits/stdc++.h>
using namespace std;
template <class T>
void printvec(const vector<T>& v) {
  for (auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}
template <class T>
void printtree(const vector<vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}
template <class T, class U>
void printmap(const map<T, U>& mp) {
  for (auto x : mp) {
    cout << x.first << "=>" << x.second << endl;
  }
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e9;
const long long MOD = 1000000007;
int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long sum = 0;
  map<long long, long long> cnt;
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
    ++cnt[A[i]];
    sum += A[i];
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q), C(Q);
  for (long long i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
  }
  for (long long i = 0; i < Q; ++i) {
    long long diff = (C[i] - B[i]) * cnt[B[i]];
    cnt[C[i]] += cnt[B[i]];
    sum += diff;
    cout << sum << endl;
  }
}
