#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
constexpr auto PI = 3.14159265358979323846264338327950L;
int needleX[4] = {-1, 0, 1, 0};
int needleY[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<int> a(N);
  map<int, int> mp;
  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    ll temp = mp[b] * b;
    ll add = c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    sum += add;
    sum -= temp;
    cout << sum << endl;
  }
  return 0;
}
