#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
int main() {
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  int cnt[110000];
  for (int i = 0; i < (110000); ++i) cnt[i] = 0;
  ll s = 0;
  for (int i = 0; i < (n); ++i) {
    cnt[a[i]]++;
    s += a[i];
  }
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    s -= cnt[b] * b;
    s += c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << s << endl;
  }
}
