#include <bits/stdc++.h>
using namespace std;
long replace(vector<int>& res, int b, int c, long all) {
  bool flag = false;
  int count = 0;
  for (int i = 0; i < res.size(); i++) {
    if (res[i] == b) {
      res[i] = c;
      flag = true;
      count++;
    }
  }
  all += (c - b) * count;
  return all;
}
int main() {
  int N, Q;
  cin >> N;
  vector<int> A;
  int all;
  for (int i = 0; i < N; i++) {
    int Ai;
    cin >> Ai;
    A.push_back(Ai);
    all += Ai;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int Bi, Ci;
    cin >> Bi >> Ci;
    all = replace(A, Bi, Ci, all);
    cout << all << endl;
  }
}
