#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 10010010010010;
const long long MOD = 1000000007;
long long mod_pow(long long N, long long M) {
  if (M == 0) return 1;
  long long res = mod_pow((N * N) % MOD, M / 2);
  if (M & 1) res = (res * N) % MOD;
  return res %= MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  vector<long long> retu(N);
  vector<long long> dict(100005);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> retu.at(i);
    dict.at(retu.at(i))++;
    ans += retu.at(i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int from, to;
    cin >> from >> to;
    int fromCount = dict.at(from);
    int minus = fromCount * from;
    int plus = fromCount * to;
    dict.at(from) = 0;
    dict.at(to) += fromCount;
    cout << ans - minus + plus << "\n";
    ;
    ans += plus;
    ans -= minus;
  }
}
