#include <bits/stdc++.h>
using namespace std;
template <typename First>
void debug_print_in(First first) {
  cerr << first << endl;
  return;
}
template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest) {
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}
void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
template <typename First>
void OUT(First first) {
  cout << first << endl;
  return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
  cout << first << " ";
  OUT(rest...);
  return;
}
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
};
template <class t, class u>
void chmin(t& a, u b) {
  if (a > b) a = b;
};
int popcount(int t) { return __builtin_popcount(t); }
int popcount(long long t) { return __builtin_popcountll(t); }
template <typename T>
void vec_print(vector<T> VEC) {
  for (long long i = (long long)0; i < (long long)VEC.size(); ++i) {
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};
template <typename T>
void mat_print(vector<vector<T>> MAT) {
  for (long long i = (long long)0; i < (long long)MAT.size(); ++i) {
    for (long long j = (long long)0; j < (long long)MAT[i].size(); ++j) {
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};
constexpr int INF = (1 << 30);
constexpr long long INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr long long MOD = (long long)((1E+9) + 7);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<long long> tmp(1E5 + 10, 0);
  long long N;
  IN(N);
  for (long long i = (long long)0; i < (long long)N; ++i) {
    long long A;
    IN(A);
    tmp[A]++;
  }
  long long Q;
  IN(Q);
  long long ans = 0;
  for (long long i = (long long)0; i < (long long)1E5 + 10; ++i) {
    ans += i * tmp[i];
  }
  for (long long q = (long long)0; q < (long long)Q; ++q) {
    long long B, C;
    IN(B, C);
    ans -= B * tmp[B];
    ans += C * tmp[B];
    tmp[C] += tmp[B];
    OUT(ans);
  }
  return 0;
}
