#include <bits/stdc++.h>
using namespace std;

#define PI acos(-1)
#define pb push_back
#define int long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 998244353
#define INF 9999999

int n;
vector<int> bit;
vector<int> m[MAXN];

int sum(int r)
{
  int ret = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1)
    ret += bit[r];
  return ret;
}
void add(int idx, int delta)
{
  for (; idx < n; idx = idx | (idx + 1))
    bit[idx] += delta;
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  bit.assign(n, 0);
  vector<int> v(n);
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    add(i, v[i]);
    m[v[i]].pb(i);
  }
  int q, l = 0, r = n - 1;
  cin >> q;
  while (q--)
  {
    int c, b;
    cin >> b >> c;
    for (auto const &i : m[b])
    {
      add(i, c - b);
      m[c].pb(i);
    }
    m[b].clear();
    cout << (sum(r) - sum(l - 1)) << endl;
  }
  return 0;
}