#include <bits/stdc++.h>
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N + 1, 0);
  ll A_sum = 0;
  for (int i = 0; i < (N); ++i) {
    int tmp;
    cin >> tmp;
    A[tmp]++;
    A_sum += tmp;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    ll B, C;
    cin >> B >> C;
    ll value = A[B];
    A[B] = 0, A[C] += value;
    A_sum = A_sum + (C - B) * value;
    cout << A_sum << endl;
  }
  return 0;
}
