#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int gcd_func(int a, int b) { return b ? gcd_func(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n, 0);
  long long sm = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sm += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    long long diff = c - b;
    int occ = count(a.begin(), a.end(), b);
    sm += occ * diff;
    cout << sm << endl;
    a.erase(remove(a.begin(), a.end(), b), a.end());
    while (occ--) {
      a.push_back(c);
    }
  }
}
