#include <bits/stdc++.h>
using namespace std;
int sum[400002];
int num[100002];
void buildSegmentTree(int at, int L, int R) {
  sum[at] = 0;
  if (L == R) {
    sum[at] = num[L];
    return;
  }
  int mid = (L + R) / 2;
  buildSegmentTree(at * 2, L, mid);
  buildSegmentTree(at * 2 + 1, mid + 1, R);
  sum[at] = sum[at * 2] + sum[at * 2 + 1];
}
void updateSegemntTreeWithNew(int at, int L, int R, int pos, int value) {
  if (pos > R || pos < L) {
    return;
  }
  if (L >= pos && R <= pos) {
    sum[at] = value;
    return;
  }
  int mid = (L + R) / 2;
  updateSegemntTreeWithNew(at * 2, L, mid, pos, value);
  updateSegemntTreeWithNew(at * 2 + 1, mid + 1, R, pos, value);
  sum[at] = sum[at * 2] + sum[at * 2 + 1];
}
long long int querySegmentTree(int at, int L, int R, int l, int r) {
  if (r < L || R < l) return 0;
  if (l <= L && R <= r) return sum[at];
  int mid = (L + R) / 2;
  long long int x = querySegmentTree(at * 2, L, mid, l, r);
  long long int y = querySegmentTree(at * 2 + 1, mid + 1, R, l, r);
  return x + y;
}
vector<int> adj[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    adj[num[i]].push_back(i);
  }
  buildSegmentTree(1, 1, n);
  int q, x, y;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    if (adj[x].size() == 0) {
    } else {
      for (int j = 0; j < adj[x].size(); j++) {
        adj[y].push_back(adj[x][j]);
        updateSegemntTreeWithNew(1, 1, n, adj[x][j], y);
      }
    }
    adj[x].clear();
    printf("%lld\n", querySegmentTree(1, 1, n, 1, n));
  }
  return 0;
}
