#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL << 60;
constexpr long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void Main() {
  int n;
  cin >> n;
  vector<int> av(10001, 0);
  int k;
  long long ans = 0;
  for (int i = (0); i < (n); ++i) {
    cin >> k;
    av[k]++;
    ans += k;
  }
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) * av[b];
    av[c] += av[b];
    av[b] = 0;
    cout << ans << "\n";
  }
  return;
}
int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(15);
  int t = 1;
  for (int _ = (0); _ < (t); ++_) Main();
  return 0;
}
