#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll INF = 1ll << 60;
void chmin(int &a, int b) {
  if (a > b) a = b;
}
void chmax(int &a, int b) {
  if (a < b) a = b;
}
void llchmin(ll &a, ll b) {
  if (a > b) a = b;
}
void llchmax(ll &a, ll b) {
  if (a < b) a = b;
}
int main() {
  int n;
  cin >> n;
  vi a(n);
  vi num(100010, 0);
  ll sum = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
    num[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = (int)(0); i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    sum = sum - b * num[b] + c * num[b];
    cout << sum << endl;
    num[c] += num[b];
    num[b] = 0;
  }
  return 0;
}
