#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> S;
int vector_find(int value, int change) {
  vector<int>::iterator it;
  int num = 0;
  it = find(a.begin(), a.end(), value);
  while (it != a.end()) {
    num++;
    *it = change;
    it = find(a.begin(), a.end(), value);
  }
  cout << "num : " << num << endl;
  return num;
}
int main() {
  int N, Q;
  int add = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    add += A;
    a.push_back(A);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    int add_new = add + vector_find(b, c) * (c - b);
    S.push_back(add_new);
    add = add_new;
  }
  for (int i = 0; i < Q; i++) {
    cout << S[i] << endl;
  }
}
