#include <bits/stdc++.h>
using namespace std;
struct value {
  long long x;
  long long y;
};
bool compare(value a, value b) {
  if (a.y < b.y)
    return 1;
  else
    return 0;
}
int main() {
  long long n;
  cin >> n;
  vector<long long> arr;
  long long q, temp;
  long long sum;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    arr.push_back(temp);
  }
  cin >> q;
  long long b, c;
  for (long long i = 0; i < q; i++) {
    sum = 0;
    cin >> b >> c;
    for (long long i = 0; i < n; i++) {
      if (arr[i] == b) arr[i] = c;
    }
    for (long long i = 0; i < n; i++) {
      sum = sum + arr[i];
    }
    cout << sum << "\n";
  }
}
