#include <bits/stdc++.h>
using namespace std;
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
inline int p(void) {
  cout << endl;
  return 0;
}
template <class Head>
int p(Head&& head) {
  cout << head;
  p();
  return 0;
}
template <class Head, class... Tail>
int p(Head&& head, Tail&&... tail) {
  cout << head << " ";
  p(forward<Tail>(tail)...);
  return 0;
}
struct ProconInit {
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    if (AUTOFLUSH) cout << unitbuf;
  }
} PROCON_INIT;
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;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first + a.second > b.first + b.second;
}
int a[100001];
signed main() {
  int n;
  IN(n);
  ;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    int A;
    IN(A);
    ;
    a[A]++;
    sum += A;
  }
  int q;
  IN(q);
  ;
  for (long long i = 0; i < q; i++) {
    int b, c;
    IN(b, c);
    ;
    sum += (c - b) * a[b];
    p(sum);
    a[c] += a[b];
    a[b] == 0;
  }
}
