#include <bits/stdc++.h>
using namespace std;
void solve(long long int test) {
  long long int n;
  cin >> n;
  multiset<long long int> s;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    sum += x;
    s.insert(x);
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    sum = sum + (y - x) * s.count(x);
    for (long long int i = 0; i < s.count(x); i++) s.insert(y);
    s.erase(x);
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
