#include <bits/stdc++.h>
using namespace std;
int INF = 100100101;
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
vector<int> vector_fixer(vector<int> a, int target, int fixer) {
  while (vector_finder(a, target)) {
    vector<int>::iterator itr;
    itr = find(a.begin(), a.end(), target);
    int index = distance(a.begin(), itr);
    a[index] = fixer;
  }
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
  }
  int sum = 0;
  for (int i = 0; i < (n); ++i) sum += a[i];
  for (int i = 0; i < (q); ++i) {
    int num = count(a.begin(), a.end(), b[i]);
    int gap = c[i] - b[i];
    sum += gap * num;
    cout << sum << endl;
    replace(a.begin(), a.end(), b[i], c[i]);
  }
  return 0;
}
