#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flg = false;
  int n, q;
  long long s = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  vector<pair<int, int>> p;
  s += a[0];
  p.push_back(make_pair(a[0], 1));
  for (int i = 1; i < n; i++) {
    s += a[i];
    for (int j = 0; j < p.size(); j++) {
      if (p.at(j).first == a[i]) {
        p.at(j).second += 1;
        flg = true;
        break;
      }
    }
    if (flg) {
      flg = false;
    } else {
      p.push_back(make_pair(a[i], 1));
    }
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < p.size(); j++) {
      if (p.at(j).first == b[i]) {
        s += (c[i] - b[i]) * (p.at(j).second);
        p.at(j).first = c[i];
      }
    }
    cout << s << endl;
  }
  return 0;
}
