#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
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;
}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);
int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (auto& i : a) cin >> i;
  ll q;
  cin >> q;
  vll b(q), c(q);
  for (ll i = (ll)(0); i < (ll)(q); i++) cin >> b.at(i) >> c.at(i);
  ll sumall = accumulate(a.begin(), a.end(), 0);
  map<ll, ll> stock;
  for (ll i = (ll)(0); i < (ll)(n); i++) {
    stock[a.at(i)]++;
  }
  for (ll i = (ll)(0); i < (ll)(q); i++) {
    if (stock.count(b.at(i))) {
      ll number = stock[b.at(i)];
      stock[b.at(i)] = 0;
      stock[c.at(i)] += number;
      sumall += number * (c.at(i) - b.at(i));
    }
    cout << sumall << endl;
  }
}
