#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
const int L = 1e5 + 10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> num(L, 0);
  for (int i = 0; i < (N); ++i) num[A[i]]++;
  long long sum = 0;
  for (int i = 0; i < (N); ++i) sum += A[i];
  for (int q = 0; q < (Q); ++q) {
    long long B, C;
    cin >> B >> C;
    long long numb = num[B];
    sum -= B * numb;
    sum += C * numb;
    num[C] += numb;
    cout << sum << "\n";
  }
  return 0;
}
