#include <bits/stdc++.h>
using namespace std;
const int64_t dx4[4] = {0, -1, 1, 0};
const int64_t dy4[4] = {-1, 0, 0, 1};
const int64_t dx5[5] = {0, -1, 0, 1, 0};
const int64_t dy5[5] = {-1, 0, 0, 0, 1};
const int64_t dx8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int64_t dy8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int64_t dx9[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
const int64_t dy9[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int get_assert_level() {
  const char* s = getenv("ASSERT_LEVEL");
  if (s) {
    return atoi(s);
  }
  return 0;
}
static int g_assert_level = get_assert_level();
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  if (g_assert_level >= 1) cerr << "LV 1" << endl;
  int N;
  cin >> N;
  vector<int64_t> count0s(200000, 0);
  int64_t sum1 = 0;
  for (int64_t i = 0; i < N; ++i) {
    int a1;
    cin >> a1;
    ++count0s[a1 - 1];
    sum1 += a1;
  }
  int Q;
  cin >> Q;
  for (int64_t i = 0; i < N; ++i) {
    int64_t b1, c1;
    cin >> b1 >> c1;
    const int64_t n_move = count0s[b1 - 1];
    count0s[b1 - 1] = 0;
    count0s[c1 - 1] += n_move;
    sum1 = sum1 - n_move * b1 + n_move * c1;
    cout << sum1 << endl;
  }
  return 0;
}
