#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
int main() {
  map<int, int> make_pair;
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    int x;
    cin >> x;
    make_pair[x]++;
  }
  ll ans = 0;
  for (auto v : make_pair) {
    ans += v.first * v.second;
  }
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    ans -= make_pair[b] * b;
    ans += make_pair[b] * c;
    make_pair[c] += make_pair[b];
    make_pair[b] = 0;
    cout << (ans) << endl;
  }
}
