#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
struct mint {
  long long x;
  mint() : x(0) {}
  mint(long long x) : x((x % mod + mod) % mod) {}
  mint& fix() {
    x = (x % mod + mod) % mod;
    return *this;
  }
  mint operator-() const { return mint(0) - *this; }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const { return mint(*this) += a; }
  mint operator-(const mint& a) const { return mint(*this) -= a; }
  mint operator*(const mint& a) const { return mint(*this) *= a; }
  bool operator<(const mint& a) const { return x < a.x; }
  bool operator==(const mint& a) const { return x == a.x; }
};
istream& operator>>(istream& i, mint& a) {
  i >> a.x;
  return i;
}
ostream& operator<<(ostream& o, const mint& a) {
  o << a.x;
  return o;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(100005);
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int A;
    cin >> A;
    a[A]++;
    sum += long long(A);
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (int)(q); i++) {
    long long sa = long long(c[i] - b[i]);
    sum += sa * a[b[i]];
    a[c[i]] += a[b[i]];
    cout << sum << endl;
  }
}
