#include <bits/stdc++.h>
using namespace std;
void mahakal() {}
const long long maxN = 1e5 + 5;
long long a[20], n, q, A, B;
map<long long, long long> mp;
void solve() {
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> A >> B;
    long long ps = mp[A];
    sum -= (ps * A);
    sum += (ps * B);
    mp.erase(A);
    mp[B] += ps;
    cout << sum << endl;
  }
}
int main() {
  long long t = 1;
  while (t--) solve();
  return 0;
}
