#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
  return is;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> p) {
  cout << '(' << p.first << ", " << p.second << ')';
  return os;
}
template <class T>
void print(const vector<T> &v, const string &delimiter = " ") {
  for (int i = 0; i < (int)(v.size()); i++)
    cout << (0 < i ? delimiter : "") << v.at(i);
  cout << endl;
}
template <class T>
void print(const vector<vector<T>> &vv, const string &delimiter) {
  for (const auto &v : vv) print(v, delimiter);
}
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;
  vector<int> cnt(100001);
  ll sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int _ = 0; _ < (int)(q); _++) {
    int b, c;
    cin >> b >> c;
    sum -= cnt[b] * b;
    sum += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
}
