#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long int it = 0, ans = 0;
long long int spf[100001];
void sieve() {
  spf[1] = 1;
  for (auto i = 2; i < 100001; i++) spf[i] = i;
  for (auto i = 4; i < 100001; i += 2) spf[i] = 2;
  for (auto i = 3; i * i < 100001; i++) {
    if (spf[i] == i) {
      for (auto j = i * i; j < 100001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
  return;
}
vector<long long int> getFactorization(long long int x) {
  vector<long long int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
struct segtree {
  long long int size;
  vector<long long int> sums;
  void init(long long int n) {
    size = 1;
    while (size < n) size *= 2;
    sums.assign(2 * size, 0LL);
  }
  void build(vector<long long int> &a, long long int x, long long int lx,
             long long int rx) {
    if (rx - lx == 1) {
      if (lx < a.size()) {
        sums[x] = a[lx];
      }
      return;
    }
    long long int m = (lx + rx) / 2;
    build(a, 2 * x + 1, lx, m);
    build(a, 2 * x + 2, m, rx);
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void build(vector<long long int> &a) { build(a, 0, 0, size); }
  void set(long long int i, long long int v, long long int x, long long int lx,
           long long int rx) {
    if (rx - lx == 1) {
      sums[x] = v;
      return;
    }
    long long int m = (lx + rx) / 2;
    if (i < m) {
      set(i, v, 2 * x + 1, lx, m);
    } else {
      set(i, v, 2 * x + 2, m, rx);
    }
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void set(long long int i, long long int v) { set(i, v, 0, 0, size); }
  long long int sum(long long int l, long long int r, long long int x,
                    long long int lx, long long int rx) {
    if (lx >= r or l >= rx) return 0;
    if (lx >= l and rx <= r) return sums[x];
    long long int m = (lx + rx) / 2;
    return sum(l, r, 2 * x + 1, lx, m) + sum(l, r, 2 * x + 2, m, rx);
  }
  long long int sum(long long int l, long long int r) {
    return sum(l, r, 0, 0, size);
  }
};
void check() {
  long long int n, sum = 0;
  cin >> n;
  segtree st;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  long long int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++)
      if (a[i] == x) a[i] = y;
    long long int ans = 0;
    for (auto i : a) ans += i;
    cout << ans << "\n";
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) check();
  return 0;
}
