#include <bits/stdc++.h>
using namespace std;
void solve(vector<long long>& v, long long a, long long b) {
  long long n = v.size();
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i] == a) v[i] = b;
    sum += v[i];
  }
  cout << sum << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  vector<long long> v;
  long long n;
  while (t--) {
    cin >> n;
    v.push_back(n);
  }
  long long m;
  cin >> m;
  long long a, b;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    solve(v, a, b);
  }
  return 0;
}
