#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long A[N], tree[4 * N];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = A[l];
  } else {
    int mid = (l + r) / 2;
    build(2 * node, l, mid);
    build(2 * node + 1, mid + 1, r);
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
void update(int node, int l, int r, int pos, int value) {
  if (l == r) {
    tree[node] = value;
  } else {
    int mid = (l + r) / 2;
    if (pos <= mid) {
      update(2 * node, l, mid, pos, value);
    } else {
      update(2 * node + 1, mid + 1, r, pos, value);
    }
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
long long query(int node, int tl, int tr, int l, int r) {
  if (r < tl || tr < l) return 0;
  if (tl >= l && tr <= r) {
    return tree[node];
  }
  int mid = (tl + tr) / 2;
  long long p1 = query(2 * node, tl, mid, l, r);
  long long p2 = query(2 * node + 1, mid + 1, tr, l, r);
  return (p1 + p2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> pos[N];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    pos[A[i]].push_back(i);
  }
  build(1, 0, n - 1);
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < (int)pos[b].size(); i++) {
      int pos_ = pos[b][i];
      update(1, 0, n - 1, pos_, c);
      pos[c].push_back(pos_);
      pos[b][i] = -1;
    }
    long long ans = query(1, 0, n - 1, 0, n - 1);
    cout << ans << "\n";
  }
  return 0;
}
