/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
const ll inf= 1e9;
const ll inf64= 1e18;
const ll MOD= 1e9 +7;



m(int,s(int)) id;
int getMid(int s, int e) { return s + (e -s)/2; }  
  

int getSumUtil(int *st, int ss, int se, int qs, int qe, int si)  
{  
    
    if (qs <= ss && qe >= se)  
        return st[si];  
   
    if (se < qs || ss > qe)  
        return 0;  
   
    int mid = getMid(ss, se);  
    return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +  
        getSumUtil(st, mid+1, se, qs, qe, 2*si+2);  
}  
  

void updateValueUtil(int *st, int ss, int se, int i, int diff, int si)  
{  
     
    if (i < ss || i > se)  
        return;  
  
     
    st[si] = st[si] + diff;  
    if (se != ss)  
    {  
        int mid = getMid(ss, se);  
        updateValueUtil(st, ss, mid, i, diff, 2*si + 1);  
        updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);  
    }  
}  
  
 
void updateValue(int arr[], int *st, int n, int i, int new_val)  
{  
    
    if (i < 0 || i > n-1)  
    {  
        cout<<"Invalid Input";  
        return;  
    }  
  
   
    int diff = new_val - arr[i];  
  
    arr[i] = new_val; 
	id[new_val].insert(i);
  
    updateValueUtil(st, 0, n-1, i, diff, 0);  
}  
  

int getSum(int *st, int n, int qs, int qe)  
{  
    // Check for erroneous input values  
    if (qs < 0 || qe > n-1 || qs > qe)  
    {  
        cout<<"Invalid Input";  
        return -1;  
    }  
  
    return getSumUtil(st, 0, n-1, qs, qe, 0);  
}  
  

int constructSTUtil(int arr[], int ss, int se, int *st, int si)  
{  
   
    if (ss == se)  
    {  
        st[si] = arr[ss];  
        return arr[ss];  
    }  
  
     
    int mid = getMid(ss, se);  
    st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +  
            constructSTUtil(arr, mid+1, se, st, si*2+2);  
    return st[si];  
}  
  

int *constructST(int arr[], int n)  
{  
    // Allocate memory for the segment tree  
  
    //Height of segment tree  
    int x = (int)(ceil(log2(n)));  
  
    //Maximum size of segment tree  
    int max_size = 2*(int)pow(2, x) - 1;  
  
    // Allocate memory  
    int *st = new int[max_size];  
  
    // Fill the allocated memory st  
    constructSTUtil(arr, 0, n-1, st, 0);  
  
    // Return the constructed segment tree  
    return st;  
}  

void Solve()
{
	int n;
	cin>>n;
	
	int a[n];
	
	f(i,0,n-1)
	{
		cin>>a[i];
		id[a[i]].insert(i);
	}
	
	int *st = constructST(a, n);
	
	int Q;
	cin>>Q;
	
	while(Q--)
	{
		int x,y;
		cin>>x>>y;
		
		fe( i,id[x]) 
		{
			updateValue(a,st,n,i,y);
		}
		id[x].clear();
		cout<< getSum(st,n,0,n-1) <<endl;
	}	
	
} 
 
signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	return 0;
} 