#include <bits/stdc++.h>
using namespace std;
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
int main() {
  int n, q;
  cin >> n;
  multiset<int> s;
  ll sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int x;
    cin >> x;
    s.insert(x);
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int a, b;
    cin >> a >> b;
    int num;
    num = s.count(a);
    s.erase(a);
    for (int j = 0; j < (int)(num); j++) s.insert(b);
    sum = sum - a * num + b * num;
    cout << sum << endl;
  }
}
