#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const long long INF = (1LL << 60);
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
bool isInteger(double x) { return floor(x) == x; }
ll ceil(ll a, ll b) { return ((a) + (b)-1) / b; }
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = ll(0); i < ll(n); i++) cin >> a[i];
  ll q;
  cin >> q;
  vector<ll> b(q), c(q);
  for (ll i = ll(0); i < ll(q); i++) cin >> b[i] >> c[i];
  map<ll, ll> mp;
  for (ll i = ll(0); i < ll(n); i++) mp[a[i]]++;
  for (ll i = ll(0); i < ll(q); i++) {
    mp[c[i]] += mp[b[i]];
    mp[b[i]] = 0;
    ll sum = 0;
    for (auto j : mp) {
      sum += j.first * j.second;
    }
    cout << sum << endl;
  }
  return 0;
}
