#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>;
const long long LINF = 1001002003004005006ll;
const long long INF = 1001001001;
const double pi = acos(-1);
int main() {
  int n;
  cin >> n;
  vector<int> a(100010, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans += x;
    a[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    int cnt = 0;
    cin >> b >> c;
    cnt = a[b];
    a[b] = 0;
    a[c] += cnt;
    ans -= b * cnt;
    ans += c * cnt;
    cout << ans << endl;
  }
  return 0;
}
