#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
ll fac[200001], finv[200001], inv[200001];
const int MX = 1000005;
const double PI = acos(-1);
int main() {
  int N;
  ll ans = 0;
  cin >> N;
  vector<int> A(100010, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ans += a;
    A[a] += 1;
  }
  int q;
  cin >> q;
  vector<ll> ANS(q);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    ans -= b * A[b];
    ans += c * A[b];
    A[c] += A[b];
    A[b] = 0;
    ANS[i] = ans;
  }
  for (int i = 0; i < q; i++) cout << ANS[i] << endl;
}
