#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<long long> graph[200001];
long long vis[200001] = {0};
long long cost[100001];
long long parent = -1;
long long costi;
void dfs(long long i) {
  vis[i] = 1;
  costi = min(cost[i], costi);
  for (auto &it : graph[i]) {
    if (vis[it] == 0) {
      dfs(it);
    }
  }
}
long long pp[100001];
bool isPrime(long long n) {
  long long i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int32_t main() {
  long long n;
  cin >> n;
  long long a[n];
  long long i;
  map<long long, long long> ma;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    ma[a[i]]++;
  }
  long long q;
  cin >> q;
  long long sum = accumulate(a, a + n, 0);
  while (q--) {
    long long x, y;
    cin >> x >> y;
    long long i;
    for (i = 0; i < n; i++) {
      if (a[i] == x) a[i] = y;
    }
    cout << accumulate(a, a + n, 0) << endl;
  }
}
