#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int n, q;
int a[112345];
int num[112345];
int cnt[112345];
int main() {
  cin >> n;
  for (ll i = 0; i < (n); ++i) cin >> a[i];
  for (ll i = 0; i < (n); ++i) cnt[a[i]]++;
  cin >> q;
  ll sum = 0;
  for (ll i = 0; i < (n); ++i) {
    sum += a[i];
  }
  for (ll i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    sum -= cnt[b] * b;
    sum += cnt[c] * c;
    cout << sum << endl;
  }
  return 0;
}
