#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD = 1e9 + 7;
const ll INF = 1ll << 60;
int N, Q;
int main() {
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < (int)(N); ++i) {
    int a;
    cin >> a;
    ++mp[a];
  }
  cin >> Q;
  vint B, C;
  for (int i = 0; i < (int)(Q); ++i) {
    int b, c;
    cin >> b >> c;
    B.emplace_back(b);
    C.emplace_back(c);
  }
  for (int i = 0; i < (int)(Q); ++i) {
    if (B.at(i) != C.at(i)) {
      mp[C.at(i)] += mp[B.at(i)];
      mp[B.at(i)] = 0;
    }
    ll sum = 0;
    for (auto str = mp.begin(); str != mp.end(); ++str) {
      sum += str->first * str->second;
    }
    cout << sum << endl;
  }
  return 0;
}
