#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF_LL = (long long)1000000007 * 1000000007;
const long long INF_INT = (long long)1000000007;
const double PI = 3.14159265358979323846;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;
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;
}
signed main() {
  long long N;
  cin >> N;
  map<long long, long long> m;
  for (long long i = (0); i < (N); ++i) {
    long long a;
    cin >> a;
    m[a]++;
  }
  long long Q;
  cin >> Q;
  vector<long long> ans(Q);
  for (long long i = (0); i < (Q); ++i) {
    long long b, c;
    cin >> b >> c;
    m[c] += m[b];
    m.erase(b);
    for (auto itr = (m).begin(); itr != (m).end(); ++itr) {
      ans[i] += (*itr).first * (*itr).second;
    }
  }
  for (long long i = (0); i < (Q); ++i) {
    cout << ans[i] << endl;
  }
}
