#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool sortKhela(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first < b.first);
}
int main() {
  c_p_c();
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int m;
  cin >> m;
  long long sum;
  while (m--) {
    sum = 0;
    int from, to;
    cin >> from >> to;
    for (int i = 0; i < n; i++) {
      if (arr[i] == from) {
        arr[i] = to;
      }
      sum += arr[i];
    }
    cout << sum << endl;
  }
  return 0;
}
