#include<stdio.h>
#include<string.h>

int main()
{
    int n, i, j, count = 0;
    scanf ("%d", &n);
    char str[n][102];
    for (i = 0; i < n; i++) {
        scanf ("%s", str[i]);
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
                count = 0;
                if (str[i][j+1]=='o')
                    count++;
                if (str[i][j-1]=='o')
                    count++;
                if (str[i+1][j]=='o')
                    count++;
                if (str[i-1][j]=='o')
                    count++;
                if (count & 1) {
                    printf ("NO\n");
                    return 0;
                }
        }
    }
    printf ("YES\n");
    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    int n, i, j, count = 0;
    scanf ("%d", &n);
    char str[n][102];
    for (i = 0; i < n; i++) {
        scanf ("%s", str[i]);
    }
    for (i = 0; i < n; i++) {
        count = 0;
        for (j = 0; j < n; j++) {
                if (str[i][j+1]=='o')
                    count++;
                if (str[i][j-1]=='o')
                    count++;
                if (str[i+1][j]=='o')
                    count++;
                if (str[i-1][j]=='o')
                    count++;
        }
       if (count & 1) {
           printf ("NO\n");
           return 0;
       }
    }
    printf ("YES\n");
    return 0;
}


#include<stdio.h>
char arr[250][250];
int main(){
    int a;
    scanf("%d",&a);
    getchar();
    int i,b;
    for(i=0;i<a;i++){
            for(b=0;b<a;b++){
                    scanf("%c",&arr[i][b]);
            }
            getchar();
    }
    for(i=0;i<a;i++){
            int cnt=0;
            for(b=0;b<a;b++){
            if(arr[i][b+1]=='o')
                cnt++;
            if(arr[i][b-1]=='o')
                cnt++;
            if(arr[i+1][b]=='o')
                cnt++;
            if(arr[i-1][b]=='o')
                cnt++;
            if(cnt%2){
            printf("NO");
            return 0;
            }
        }

    }
        printf("YES");

}


/*
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Input

The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
Output

Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
Sample test(s)
Input

3
xxo
xox
oxx

Output

YES

Input

4
xxxo
xoxo
oxox
xxxx

Output

NO
*/

#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	char arr[n][n],in[n];
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%s",in);
		for(j=0;in[j]!='\0';j++)
		{
			arr[i][j]=in[j];
		}
	}
	int c=0;
	int flag=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			c=0;
			if(arr[i][j]=='x')
			{
				if(j-1>-1 && arr[i][j-1]=='o') c++;
				if(i-1>-1 && arr[i-1][j]=='o') c++;
				if(j+1<n && arr[i][j+1]=='o') c++;
				if(i+1<n && arr[i+1][j]=='o') c++;
			}
			if(c%2!=0)
				 flag=1;
		}

	}
	if(flag==0) printf("YES\n");
	else	    printf("NO\n");
return 0;
}


/*
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Input

The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
Output

Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
Sample test(s)
Input

3
xxo
xox
oxx

Output

YES

Input

4
xxxo
xoxo
oxox
xxxx

Output

NO
*/

#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	char arr[n][n],in[n];
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%s",in);
		for(j=0;in[j]!='\0';j++)
		{
			arr[i][j]=in[j];
		}
	}
	int c=0;
	int flag=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			c=0;
			//if(arr[i][j]=='x')
			{
				if(j-1>-1 && arr[i][j-1]=='o') c++;
				if(i-1>-1 && arr[i-1][j]=='o') c++;
				if(j+1<n && arr[i][j+1]=='o') c++;
				if(i+1<n && arr[i+1][j]=='o') c++;
			}
			if(c%2!=0)
				 flag=1;
		}

	}
	if(flag==0) printf("YES\n");
	else	    printf("NO\n");
return 0;
}


#include <stdio.h>

int n, i, j, sum;
char a[105][105];

int main () {
	scanf(" %d",&n);
	for(i = 0 ; i < n ; i++){
		sum = 0;
		for(j = 0 ; j < n ; j++){
			scanf(" %c",&a[i][j]);
			sum += a[i][j] == 'o';
		}
		if(sum != 1){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


#include <stdio.h>

#define MAXN 100

typedef enum bool {FALSE,TRUE} bool;

int n;
int a [MAXN+1][MAXN+1];

int main (void) {
	scanf("%d",&n);
	int i, j;
	char s [MAXN+1];
	for (i=1; i<=n; i++) {
		scanf("%s",s);
		for (j=1; j<=n; j++) {
			if (s[j-1]=='x')
				a[i][j] = 0;
			else
				a[i][j] = 1;
		}
	}
	for (i=0; i<=n+1; i++)
		a[i][0] = a[i][n+1] = 0;
	for (j=1; j<=n; j++)
		a[0][j] = a[n+1][j] = 0;
	bool ok = TRUE;
	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			if ((a[i-1][j]+a[i][j-1]+a[i+1][j]+a[i][j+1])%2==1) {
				ok = FALSE;
				break;
			}
		}
		if (!ok)
			break;
	}
	if (ok)
		puts("YES");
	else
		puts("NO");
	return 0;
}


#include <stdio.h>

#define MAXN 100

typedef enum bool {FALSE,TRUE} bool;

int n;
int a [MAXN+2][MAXN+2];

int main (void) {
	scanf("%d",&n);
	int i, j;
	char s [MAXN+1];
	for (i=1; i<=n; i++) {
		scanf("%s",s);
		for (j=1; j<=n; j++) {
			if (s[j-1]=='x')
				a[i][j] = 0;
			else
				a[i][j] = 1;
		}
	}
	for (i=0; i<=n+1; i++)
		a[i][0] = a[i][n+1] = 0;
	for (j=1; j<=n; j++)
		a[0][j] = a[n+1][j] = 0;
	bool ok = TRUE;
	for (i=1; i<=n; i++) {
		for (j=1; j<=n; j++) {
			if ((a[i-1][j]+a[i][j-1]+a[i+1][j]+a[i][j+1])%2==1) {
				ok = FALSE;
				break;
			}
		}
		if (!ok)
			break;
	}
	if (ok)
		puts("YES");
	else
		puts("NO");
	return 0;
}


#include<stdio.h>
#include<string.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
int main(){
  int n,t;
  char u,d,r,l;
  scanf("%d",&n);
  char cb[n][n];
  loop(i,0,n){
    scanf("%s",cb[i]);
  }
  loop(i,0,n){
    loop(j,0,n){
      t=0
      u = cb[i-1][j];
      d = cb[i+1][j];
      r = cb[i][j+1];
      l = cb[i][j-1];
      if(u=='o'||u=='x'){
        if(u=='o') t++;
      }
      if(d=='o'||d=='x'){
        if(d=='o') t++;
      }
      if(r=='o'||r=='x'){
        if(r=='o') t++;
      }
      if(l=='o'||l=='x'){
        if(l=='o') t++;
      }
      if(t%2==0) continue;
      else{
        goto no;
      }
    }
  }
  printf("YES");
  return(0);
  no:
  printf("NO");
  return(0);
}


#include<stdio.h>
char ar[100][100];
int check_horizontal(int a, int b,int n)
{
	int counter=0;
	for(int j=0;j<n;j++)
	{
		if(ar[a][j]=='o'&& j!=b)
		counter++;
	}
	return counter;
}
int check_vertical(int a, int b,int n)
{
	int counter=0;
	for(int j=0;j<n;j++)
	{
		if(ar[j][b]=='o'&& j!=a)
		counter++;
	}
	return counter;
}
int check_possible(int n)
{
	int h,v;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			h=check_horizontal(i,j,n);
			v=check_vertical(i,j,n);
			if((v+h)%2!=0)
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n,flag=1;
	char str[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
	  scanf("%s",&str);
	  for(int j=0;j<n;j++)
	  ar[i][j]=str[j];
	}
	flag=check_possible(n);
	if(flag==1)
	printf("YES");
	if(flag==0)
	printf("NO");
	return 0;
}


#include<stdio.h>
char ar[100][100];
int check_horizontal(int a, int b,int n)
{
	int counter=0;
	if((b-1)>=0 && ar[a][b-1]=='o')
	counter++;
	if((a-1)>=0 && ar[a-1][b]=='o')
	counter++;
	if((b+1)<=(n-1) && ar[a][b+1]=='o')
	counter++;
	if((a+1)<=(n-1) && ar[a+1][b]=='o')
	counter++;
	return counter;
}
int check_possible(int n)
{
	int h,i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			h=check_horizontal(i,j,n);
			if(h%2!=0)
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n,flag=1,i,j;
	char str[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	  scanf("%s",&str);
	  for(j=0;j<n;j++)
	  ar[i][j]=str[j];
	}
	flag=check_possible(n);
	if(flag==1)
	printf("YES");
	if(flag==0)
	printf("NO");
	return 0;
}


#include<stdio.h>
char ar[100][100];
int check_horizontal(int a, int b,int n)
{
	int counter=0,j;
	for(j=0;j<n;j++)
	{
		if(ar[a][j]=='o'&& j!=b)
		counter++;
	}
	return counter;
}
int check_vertical(int a, int b,int n)
{
	int counter=0,j;
	for(j=0;j<n;j++)
	{
		if(ar[j][b]=='o'&& j!=a)
		counter++;
	}
	return counter;
}
int check_possible(int n)
{
	int h,v,i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			h=check_horizontal(i,j,n);
			v=check_vertical(i,j,n);
			if((v+h)%2!=0)
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n,flag=1,i,j;
	char str[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	  scanf("%s",&str);
	  for(j=0;j<n;j++)
	  ar[i][j]=str[j];
	}
	flag=check_possible(n);
	if(flag==1)
	printf("YES");
	if(flag==0)
	printf("NO");
	return 0;
}


#include<stdio.h>
int main () {

    char x[100][101] ;
    int n, i, j , k ;

    int counter = 0  ;

    scanf ("%d" , &n) ;

    for ( i = 0 ; i < n ; i++)
        scanf ("%s" , x[i]) ;

    for ( i = 0 ; i < n ; i++ ){

        for ( j = 0 ; j < n ; j++ ){

            counter = 0 ;

            for ( k = 0 ; k < n ; k++){

                if ( x[i][k] == 'o' ) counter++ ;
            }

            for ( k = 0 ; k < n ; k++){
                if ( x[k][j] == 'o' ) counter++ ;
            }

            if ( x[i][j] == 'o') counter-=2 ;

            if ( counter % 2 ){
                puts ("NO") ;
                return 0 ;
            }
        }
    }
        puts ("YES") ;
        return 0 ;
    }


#include<stdio.h>
int main () {

    int i ,n , j;
    char c[100][101] ;

    scanf ("%d" , &n) ;

    int counter ;

    for(i = 0; i < n; ++i)

            scanf ("%s" , c[i] ) ;

    for(i = 0; i < n; ++i){

        counter= 0;
        for(j = 0; j < n; ++j){
            if ( i -1 >= 0 )
            if(c[i - 1][j] == 'o')
                counter++;

            if ( i + 1 < n )
            if(c[i + 1][j] == 'o')
                counter++;

            if ( j - 1 >= 0 )
            if(c[i][j - 1] == 'o')
                counter++;
            if ( j + 1 < n  )
            if(c[i][j + 1] == 'o')

                counter++;

            if( counter % 2 )
            {
                puts ("NO") ;
                return 0 ;
            }
        }
    }
    puts ("YES") ;
    return 0;
}


#include<stdio.h>
int main () {

    int i ,n , j;
    char c[100][100] ;

    scanf ("%d" , &n) ;

    int counter ;

    for(i = 0; i < n; ++i)

            scanf ("%s" , c[i] ) ;

    for(i = 0; i < n; ++i){

        counter= 0;
        for(j = 0; j < n; ++j){
            if ( i -1 >= 0 )
            if(c[i - 1][j] == 'o')
                counter++;

            if ( i + 1 <= n )
            if(c[i + 1][j] == 'o')
                counter++;

            if ( j - 1 >= 0 )
            if(c[i][j - 1] == 'o')
                counter++;
            if ( j + 1 <= n  )
            if(c[i][j + 1] == 'o')

                counter++;

            if( counter % 2 )
            {
                puts ("NO") ;
                return 0 ;
            }
        }
    }
    puts ("YES") ;
    return 0;
}


#include<stdio.h>
int main () {

    int i ,n , j;
    char c[100][101] ;

    scanf ("%d" , &n) ;

    int counter ;

    for(i = 0; i < n; ++i)

            scanf ("%s" , c[i] ) ;

    for(i = 0; i < n; ++i){

        counter= 0;
        for(j = 0; j < n; ++j){
            if ( i -1 >= 0 )
            if(c[i - 1][j] == 'o')
                counter++;

            if ( i + 1 <= n )
            if(c[i + 1][j] == 'o')
                counter++;

            if ( j - 1 >= 0 )
            if(c[i][j - 1] == 'o')
                counter++;
            if ( j + 1 <= n  )
            if(c[i][j + 1] == 'o')

                counter++;

            if( counter % 2 )
            {
                puts ("NO") ;
                return 0 ;
            }
        }
    }
    puts ("YES") ;
    return 0;
}


#include <iostream>
using namespace std;
int main () {

    char x[100][101] ;
    int n, i, j , k ;

    int counter = 0  ;

    cin >> n ;

    for ( i = 0 ; i < n ; i++)
        cin >> x[i] ;

    for ( i = 0 ; i < n ; i++ ){

        for ( j = 0 ; j < n ; j++ ){

            counter = 0 ;

            for ( k = 0 ; k < n ; k++){

                if ( x[i][k] == 'o' ) counter++ ;
            }

            for ( k = 0 ; k < n ; k++){
                if ( x[k][j] == 'o' ) counter++ ;
            }

            if ( x[i][j] == 'o') counter-=2 ;

            if ( counter % 2 ){
                puts ("NO") ;
                return 0 ;
            }
        }
    }
        puts ("YES") ;
        return 0 ;
    }


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char arr[n+1][n+1];
	int i, j, k;
	int r, c;
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
			scanf("%s", arr[i]);
	}
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
		{
			int rowNbr[4] = {-1, 0, 0, 1};
			int colNbr[4] = {0, -1, 1, 0};
			int i;
			int count = 0;
			for(k=0; k<4; k++)
			{
				int c = j+colNbr[k];
				int r = i+rowNbr[k];
				if((c>=0 && c<n) && (r>=0 && r<n) && (arr[r][c] == 'o'))
					count++;
			}
			if(count&1)
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char arr[n+1][n+1];
	int i, j, k;
	int r, c;
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
			scanf(" %c", &arr[i][j]);
	}
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
		{
			int rowNbr[4] = {-1, 0, 0, 1};
			int colNbr[4] = {0, -1, 1, 0};
			int i;
			int count = 0;
			for(k=0; k<4; k++)
			{
				int c = j+colNbr[k];
				int r = i+rowNbr[k];
				if((c>=0 && c<n) && (r>=0 && r<n) && (arr[r][c] == 'o'))
					count++;
			}
			if(count&1)
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char arr[n+1][n+1];
	int i, j, k;
	int r, c;
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
			scanf(" %c", &arr[i][j]);
	}
	for(i=0; i<n; i++)
	{
		for(j=0; j<n; j++)
		{
			int rowNbr[4] = {-1, 0, 0, 1};
			int colNbr[4] = {0, -1, 1, 0};
			int i;
			int count = 0;
			for(k=0; k<4; k++)
			{
				int c = j+colNbr[k];
				int r = i+rowNbr[k];
				if((c>=0 && c<n) && (r>=0 && r<n) && (arr[r][c] == 'o'))
					count++;
			}
			if(count&1 || (count&2 && arr[i][j] == 'o'))
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main (int argc, char * argv[]) {
    int n;
    scanf ("%d\n", &n);

    char black_hole;
    char ** board = (char **) malloc (sizeof(char *) * n);
    for (int i = 0; i < n; i++) {
        board[i] = (char *) malloc (sizeof(char) * n);
        for (int j = 0; j < n; j++) {
            scanf ("%c", &board[i][j]);
        }
        scanf ("%c", &black_hole); // The tailing '\n'
    }

    bool ok = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int os = 0;
            if (i > 0 && 'o' == board[i - 1][j]) {
                os++;
            }
            if (i < n - 1 && 'o' == board[i + 1][j]) {
                os++;
            }
            if (j > 0 && 'o' == board[i][j - 1]) {
                os++;
            }
            if (j < n - 1 && 'o' == board[i][j + 1]) {
                os++;
            }
            if (os % 2 != 0) {
                ok = false;
                break;
            }
        }
    }

    if (ok) {
        printf ("YES\n");
    } else {
        printf ("NO\n");
    }

    for (int i = 0; i < n; i++) {
        free (board[i]);
    }
    free (board);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main (int argc, char * argv[]) {
    int n;
    scanf ("%d\n", &n);

    char black_hole;
    char ** board = (char **) malloc (sizeof(char *) * n);
    for (int i = 0; i < n; i++) {
        board[i] = (char *) malloc (sizeof(char) * n);
        for (int j = 0; j < n; j++) {
            scanf ("%c", &board[i][j]);
        }
        scanf ("%c", &black_hole); // The tailing '\n'
    }

    bool ok = true;
    for (int i = 0; i < n; i++) {
        int os = 0;
        for (int j = 0; j < n; j++) {
            if (i > 0 && 'o' == board[i - 1][j]) {
                os++;
            }
            if (i < n - 1 && 'o' == board[i + 1][j]) {
                os++;
            }
            if (j > 0 && 'o' == board[i][j - 1]) {
                os++;
            }
            if (j < n - 1 && 'o' == board[i][j + 1]) {
                os++;
            }
        }
        if (os % 2 != 0) {
            ok = false;
            break;
        }
    }

    if (ok) {
        printf ("YES\n");
    } else {
        printf ("NO\n");
    }

    for (int i = 0; i < n; i++) {
        free (board[i]);
    }
    free (board);
    return 0;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char mat[n+1][n+1];
    int i, j, count=0;
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%c", &mat[i][j]);
        }
    }
    for(i=0; i<n-1; i++)
    {
          count=0;
        for(j=0; j<n; j++)
        {
            if(mat[i-1][j]=='o')
                count++;
            if(mat[i+1][j]=='o')
                count++;
            if(mat[i][j+1]=='o')
                count++;
            if(mat[i][j-1]=='o')
                count++;
               // printf("%d ", count);
         if(count%2!=0)
         {
             printf("NO");
             return 0;
         }
        }

    }
    printf("YES");
    return 0;
}


#include <stdio.h>
int main() {
	char tempc;
	int a[104][104] = {0};
	int i, flag = 0, n, j, temp;

	// STDIN
	scanf("%d\n", &n);
    for(i=1; i<=n; i++) {
		for(j=1; j<=n; j++) {
			scanf("%c", &tempc);
			if(tempc == 'o') a[i][j] = 1;
		}
		scanf("%c", &temp);
	}

	// GO ON
	for(i=1; i<=n; i++)
		for(j=1; j<=n; j++) {
			temp = a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1];
			if(temp%2 != 0) flag = 1;
		}

	if(flag == 1) printf("NO");
	else printf("YES");

	return 0;
}


#include <stdio.h>
int main() {
	char tempc;
	int a[101][101] = {0};
	int i, flag = 0, n, j, temp;

	// STDIN
	scanf("%d\n", &n);
    for(i=1; i<=n; i++) {
		for(j=1; j<=n; j++) {
			scanf("%c", &tempc);
			if(tempc == 'o') a[i][j] = 1;
		}
		scanf("%c", &temp);
	}

	// GO ON
	for(i=1; i<=n; i++)
		for(j=1; j<=n; j++) {
			temp = a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1];
			if(temp%2 != 0) flag = 1;
		}

	if(flag == 1) printf("NO");
	else printf("YES");

	return 0;
}


#include<stdio.h>
check1(int ,int,int);
check2(int,int,int,int);
check3(int,int ,int);
check4(int,int,int,int);
int main()
{
    int n,i,j,c=0,count,u;
    char chk[100][100];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
            scanf("%s",&chk[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            count=0;
            if(chk[i-1][j]=='o')
                count++;
            if(chk[i+1][j]=='o')
                count++;
            if(chk[i][j+1]=='o')
                count++;
            if(chk[i][j-1]=='o')
                count++;
            u=count%2;
            if(u==1)
            {
                c=1;
                break;
            }
            else
                continue;
        }
        if(c==1)
            break;
        else
            continue;
    }
    if(c==1)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}


//In the name of good
#include <bits/stdc++.h>
using namespace std ;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define X first
#define y1 asdfghj
#define Y second
#define ST setprecision ( 12 )
const long double pi = 3.1415926535897932384626433832795 ;
const int maxn =  505 ;
const int maxL = 22 ;
const int base = 127 ;
const int mod = 8e7 + 7 ;
const int inf = 1e16 ;
typedef long double ld ;
typedef pair < int , int > pii ;
typedef pair < pii , int > piii ;
int n , m , q ;
vector < pii > edge ;
vector < int > vc [ maxn ] ;
map < int , int > dp [ 10004 ] ;

void init ( )
{
  cin >> n >> m ;
  int a , b ;
  for ( int i = 0 ; i < m ; i ++ )
    {
      cin >> a >> b ;
      a -- ;
      b -- ;
      edge . push_back ( pii ( a , b ) ) ;
      vc [ a ] . push_back ( b ) ;
      vc [ b ] . push_back ( a ) ;
    }
}
int par [ 505 ] , ans ;

void get_par ( int &x )
{
  if ( par [ x ] == -1 )
    return ;
  if ( par [ par [ x ] ] == -1 )
    {
      x = par [ x ] ;
      return ;
    }
    par [ x ] = par [ par [ x ] ] ;
  return get_par ( x ) ;
}

void add ( int v , int u )
{
  get_par ( v ) ;
  get_par ( u ) ;
  if ( u == v )
    ;
  else
    {
      ans -- ;
      par [ u ] = v ;
    }
}

void get ( )
{
  for ( int i = 0 ; i < m ; i ++ )
    {
      ans = n ;
      fill ( par , par + 502 , -1 ) ;
      for ( int j = 0 ; j < i ; j ++ )
	add ( edge [ j ] . X , edge [ j ] . Y ) ;
      dp [ i ] [ m - 1 ] = ans ;
      for ( int j = m - 1 ; j > i ; j -- )
	{
	  add ( edge [ j ] . X , edge [ j ] . Y ) ;
	  dp [ i ] [ j - 1 ] = ans ;
	}
    }
}

main ( )
{
  fast ;
  init ( ) ;
  get ( ) ;
  cin >> q ;
  int a , b ;
  while ( q -- )
    {
      cin >> a >> b ;
      a -- ;
      b -- ;
      cout << dp [ a ] [ b ] << endl ;
    }
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 18;
const int MaxM = 1 << 18;
const int MaxBlockSize = 1 << 9;

int N, M, A[MaxN], B[MaxN], BlockValue[MaxBlockSize], ElementzValue[MaxN], t[MaxM], X[MaxM], Y[MaxM], K[MaxM];

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = 0; i < N; i++ ) cin >> B[i];

    int BlockSize = 1;
    while ( BlockSize * BlockSize <= N ) BlockSize++;

    memset ( BlockValue, -1, sizeof ( BlockValue ) );
    memset ( ElementzValue, -1, sizeof ( ElementzValue ) );
    BlockSize = 350;
    for ( int i = 0; i < M; i++ )
    {
        cin >> t[i] >> X[i];
        X[i]--;

        if ( t[i] == 1 )
        {
            cin >> Y[i] >> K[i];
            Y[i]--;

            int L = Y[i], R = Y[i] + K[i] - 1;
            int idxL = L / BlockSize, idxR = R / BlockSize;

            if ( idxL != idxR )
            {
                for ( int j = idxL + 1; j <= idxR - 1; j++ ) BlockValue[j] = i;

                if ( BlockValue[idxL] != -1 ) for ( int j = 0; j < BlockSize; j++ ) ElementzValue[idxL * BlockSize + j] = BlockValue[idxL];
                if ( BlockValue[idxR] != -1 ) for ( int j = 0; j < BlockSize; j++ ) ElementzValue[idxR * BlockSize + j] = BlockValue[idxR];
                BlockValue[idxL] = BlockValue[idxR] = -1;
                for ( int j = L; j < ( idxL + 1 ) * BlockSize; j++ ) ElementzValue[j] = i;
                for ( int j = idxR * BlockSize; j <= R; j++ ) ElementzValue[j] = i;
            }
            else
            {
                if ( BlockValue[idxL] != -1 ) for ( int j = idxL * BlockSize; j < ( idxL + 1 ) * BlockSize; j++ ) ElementzValue[j] = BlockValue[idxL];
                BlockValue[idxL] = -1;
                for ( int j = L; j <= R; j++ ) ElementzValue[j] = i;
            }
        }
        else
        {
            int Pos = X[i];
            if ( ElementzValue[Pos] == -1 ) cout << B[Pos] << endl;
            else
            {
                int idxPos = Pos / BlockSize, idx = -1;
                if ( BlockValue[idxPos] != -1 ) idx = BlockValue[idxPos];
                else idx = ElementzValue[Pos];

                cout << A[X[idx] + Pos - Y[idx]] << endl;
            }
        }
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;

typedef struct Edge
{
    int idx, Pos;
    Edge ( ) { }
    Edge ( int __idx, int __Pos ) : idx ( __idx ), Pos ( __Pos ) { }
};

int N, M, K, L, R;
bool Visited[MaxN];
vector < Edge > E[MaxN];

void DFS ( int Curr )
{
    Visited[Curr] = true;
    for_each ( it, E[Curr] ) if ( ! Visited[it -> idx] && ( it -> Pos < L || it -> Pos > R ) ) DFS ( it -> idx );
}

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 0; i < M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        E[idx].pb ( Edge ( idy, i ) );
        E[idy].pb ( Edge ( idx, i ) );
    }

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        cin >> L >> R;
        L--;
        R--;

        memset ( Visited, -1, sizeof ( Visited ) );

        int Cnt = 0;
        for ( int j = 0; j < N; j++ ) if ( ! Visited[j] ) Cnt++, DFS ( j );
        cout << Cnt << endl;
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;
const int MaxM = 1 << 14;

int N, M, K, L, R;
pii Edges[MaxM];

typedef struct DisjointSet
{
    int Parent[MaxN], Size[MaxN];

    inline void init ( void )
    {
        for ( int i = 0; i < N; i++ ) Parent[i] = i, Size[i] = 1;
    }

    inline int find ( int idx )
    {
        if ( Parent[idx] != idx ) return Parent[idx] = find ( Parent[idx] );
        else return idx;
    }

    inline int count ( void )
    {
        int Cnt = 0;
        for ( int i = 0; i < N; i++ ) if ( Size[i] ) Cnt++;
        return Cnt;
    }

    inline void merge ( int idx, int idy )
    {
        idx = find ( idx ), idy = find ( idy );
        if ( idx != idy )
        {
            if ( Size[idx] > Size[idy] ) Parent[idy] = idx, Size[idx] += Size[idy], Size[idy] = 0;
            else Parent[idx] = idy, Size[idy] += Size[idx], Size[idx] = 0;
        }
    }
};

DisjointSet Prefix[MaxN], Suffix[MaxN];

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 0; i < M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        Edges[i] = make_pair ( idx, idy );

        Prefix[i].init ( );
        Suffix[i].init ( );
    }

    for ( int i = 0; i < M; i++ )
    {
        if ( i != 0 ) Prefix[i] = Prefix[i - 1];
        Prefix[i].merge ( Edges[i].first, Edges[i].second );
    }
    for ( int i = M - 1; i >= 0; i-- )
    {
        if ( i != M - 1 ) Suffix[i] = Suffix[i + 1];
        Suffix[i].merge ( Edges[i].first, Edges[i].second );
    }

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        int L, R;
        cin >> L >> R;
        L -= 2;

        DisjointSet Left, Right;
        Left.init ( );
        Right.init ( );

        if ( L >= 0 ) Left = Prefix[L];
        if ( R < M ) Right = Suffix[R];

        for ( int j = 0; j < N; j++ ) Left.merge ( j, Right.find ( j ) );
        cout << Left.count ( ) << endl;
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;
const int MaxM = 1 << 14;

int N, M, K, L, R;
pii Edges[MaxM];

typedef struct DisjointSet
{
    int Cnt, Parent[MaxN], Size[MaxN];
    DisjointSet ( ) { }

    inline void init ( void )
    {
        for ( int i = 0; i < N; i++ ) Parent[i] = i, Size[i] = 1;
        Cnt = N;
    }

    inline int find ( int idx )
    {
        if ( Parent[idx] != idx ) return Parent[idx] = find ( Parent[idx] );
        else return idx;
    }

    inline int count ( void )
    {
        int Cnt = 0;
        for ( int i = 0; i < N; i++ ) if ( Size[i] ) Cnt++;
        return Cnt;
    }

    inline void merge ( int idx, int idy )
    {
        idx = find ( idx ), idy = find ( idy );
        if ( idx != idy )
        {
            if ( Size[idx] > Size[idy] ) Parent[idy] = idx, Size[idx] += Size[idy], Size[idy] = 0;
            else Parent[idx] = idy, Size[idy] += Size[idx], Size[idx] = 0;

            Cnt--;
        }
    }
};

DisjointSet Prefix[MaxM], Suffix[MaxM];

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 1; i <= M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        Edges[i] = make_pair ( idx, idy );
    }

    Prefix[0].init ( );
    for ( int i = 1; i <= M; i++ ) Prefix[i] = Prefix[i - 1], Prefix[i].merge ( Edges[i].first, Edges[i].second );
    Suffix[M + 1].init ( );
    for ( int i = M; i >= 1; i-- ) Suffix[i] = Suffix[i + 1], Suffix[i].merge ( Edges[i].first, Edges[i].second );

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        int L, R;
        cin >> L >> R;
        DisjointSet Left = Prefix[L - 1], Right = Suffix[R + 1];

        for ( int j = 0; j < N; j++ ) Left.merge ( j, Right.find ( j ) );
        cout << Left.Cnt << endl;
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;

typedef struct Edge
{
    int idx, Pos;
    Edge ( ) { }
    Edge ( int __idx, int __Pos ) : idx ( __idx ), Pos ( __Pos ) { }
};

int N, M, K, L, R;
bool Visited[MaxN];
vector < Edge > E[MaxN];

void DFS ( int Curr )
{
    Visited[Curr] = true;
    for_each ( it, E[Curr] ) if ( ! Visited[it -> idx] && ( it -> Pos < L || it -> Pos > R ) ) DFS ( it -> idx );
}

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 0; i < M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        E[idx].pb ( Edge ( idy, i ) );
        E[idy].pb ( Edge ( idx, i ) );
    }

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        cin >> L >> R;
        L--;
        R--;

        memset ( Visited, false, sizeof ( Visited ) );

        int Cnt = 0;
        for ( int j = 0; j < N; j++ ) if ( ! Visited[j] ) Cnt++, DFS ( j );
        cout << Cnt << endl;
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;
const int MaxM = 1 << 14;

int N, M, K, L, R;
pii Edges[MaxM];

typedef struct DisjointSet
{
    int N, Parent[MaxN], Size[MaxN];
    DisjointSet ( ) { }

    inline void init ( void )
    {
        for ( int i = 0; i < N; i++ ) Parent[i] = i, Size[i] = 1;
        Cnt = N;
    }

    inline int find ( int idx )
    {
        if ( Parent[idx] != idx ) return Parent[idx] = find ( Parent[idx] );
        else return idx;
    }

    inline int count ( void )
    {
        int Cnt = 0;
        for ( int i = 0; i < N; i++ ) if ( Size[i] ) Cnt++;
        return Cnt;
    }

    inline void merge ( int idx, int idy )
    {
        idx = find ( idx ), idy = find ( idy );
        if ( idx != idy )
        {
            if ( Size[idx] > Size[idy] ) Parent[idy] = idx, Size[idx] += Size[idy], Size[idy] = 0;
            else Parent[idx] = idy, Size[idy] += Size[idx], Size[idx] = 0;

            Cnt--;
        }
    }
};

DisjointSet Prefix[MaxN], Suffix[MaxN];

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 1; i <= M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        Edges[i] = make_pair ( idx, idy );
    }

    Prefix[0].init ( );
    for ( int i = 1; i <= M; i++ ) Prefix[i] = Prefix[i - 1], Prefix[i].merge ( Edges[i].first, Edges[i].second );
    Suffix[M + 1].init ( );
    for ( int i = M; i >= 1; i-- ) Suffix[i] = Suffix[i + 1], Suffix[i].merge ( Edges[i].first, Edges[i].second );

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        int L, R;
        cin >> L >> R;
        DisjointSet Left = Prefix[L - 1], Right = Suffix[R + 1];

        for ( int j = 0; j < N; j++ ) Left.merge ( j, Right.find ( j ) );
        cout << Left.Cnt << endl;
    }

    return 0;
}


/*
    Aleksandar "Al3kSaNdaR" Ivanović

    292D - Connected Components
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <functional>

#define pb push_back
#define sz size
#define all(X) (X).begin(), (X).end ()
#define for_each(it, X) for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

using namespace std;

typedef long long int lld;
typedef pair < int, int > pii;

const int MaxN = 1 << 9;
const int MaxM = 1 << 14;

int N, M, K, L, R;
pii Edges[MaxM];

typedef struct DisjointSet
{
    int Cnt, Parent[MaxN], Size[MaxN];
    DisjointSet ( ) { }

    inline void init ( void )
    {
        for ( int i = 0; i < N; i++ ) Parent[i] = i, Size[i] = 1;
        Cnt = N;
    }

    inline int find ( int idx )
    {
        if ( Parent[idx] != idx ) return Parent[idx] = find ( Parent[idx] );
        else return idx;
    }

    inline int count ( void )
    {
        int Cnt = 0;
        for ( int i = 0; i < N; i++ ) if ( Size[i] ) Cnt++;
        return Cnt;
    }

    inline void merge ( int idx, int idy )
    {
        idx = find ( idx ), idy = find ( idy );
        if ( idx != idy )
        {
            if ( Size[idx] > Size[idy] ) Parent[idy] = idx, Size[idx] += Size[idy], Size[idy] = 0;
            else Parent[idx] = idy, Size[idy] += Size[idx], Size[idx] = 0;

            Cnt--;
        }
    }
};

DisjointSet Prefix[MaxN], Suffix[MaxN];

int main ( void )
{
    cin.sync_with_stdio ( 0 );
    cout.sync_with_stdio ( 0 );

    cin >> N >> M;
    for ( int i = 1; i <= M; i++ )
    {
        int idx, idy;
        cin >> idx >> idy;
        idx--;
        idy--;

        Edges[i] = make_pair ( idx, idy );
    }

    Prefix[0].init ( );
    for ( int i = 1; i <= M; i++ ) Prefix[i] = Prefix[i - 1], Prefix[i].merge ( Edges[i].first, Edges[i].second );
    Suffix[M + 1].init ( );
    for ( int i = M; i >= 1; i-- ) Suffix[i] = Suffix[i + 1], Suffix[i].merge ( Edges[i].first, Edges[i].second );

    cin >> K;
    for ( int i = 0; i < K; i++ )
    {
        int L, R;
        cin >> L >> R;
        DisjointSet Left = Prefix[L - 1], Right = Suffix[R + 1];

        for ( int j = 0; j < N; j++ ) Left.merge ( j, Right.find ( j ) );
        cout << Left.Cnt << endl;
    }

    return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];
bool vis[maxN];
void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(!vis[G[cnt][i].first] and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
    }
  scanf("%d", &k);
  while(k--)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      fill(vis+1,vis+n+1,false);
      for(int j=1;j<n+1;j++)
	{
	  if(!vis[j])
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

const int maxM=1e4+20;
const int maxN=500+19;
pair<int , int>  e[maxM];
int parent[maxN],rank[maxN],n,m,k;

inline int Find(int x)
{
  if(parent[x]!=x)
    parent[x]=Find(parent[x]);
  return parent[x];
}
inline void Union(int x, int y)
{
  int xroot,yroot;
  xroot=Find(x);
  yroot=Find(y);
  if(xroot!=yroot)
    {
      if(rank[xroot]<rank[yroot])
	{
	  parent[xroot]=yroot;
	}
      else if(rank[xroot]>rank[yroot])
	{
	  parent[yroot]=xroot;
	}
      else
	{
	  parent[yroot]=xroot;
	  rank[xroot]=rank[xroot]+1;
	}
    }
}
void solve(int l,int r)
{
  for(int i=0;i<n;i++)
    {
      parent[i]=i;
      rank[i]=0;
    }
  int cnt=n;
  LOOP(i,m)
    {
      if(i>r or i<l)
	{
	  int c1,c2;
	  c1=Find(e[i].X);c2=Find(e[i].Y);
	  if(c1!=c2)
	    {
	      Union(e[i].X,e[i].Y);cnt--;
	    }
	}
     }
  cout<<cnt<<'\n';
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  int r,l;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      e[i]=mp(u,v);
    }
  cin>>k;
  LOOP(i,k)
    {
      cin>>l>>r;
      l--,r--;
      solve(l,r);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,r,l,cur;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(root<l and root>r)
	{
	  if(vis[v]!=cur)
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      cur=i+1;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,sz[500+70];
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u,int cur,int l,int r)
{
  vis[u].pb(cur);
  LOOP(i, sz[u] )
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=vis[v].back();
      if(h!=cur )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v,cur,l,r);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));
      sz[u]++;
      sz[v]++;
    }
  LOOP(i,n+1)
    {
      vis[i].pb(-1);
    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      int r,l;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  int h=vis[j].back();
	  if(h!=i)
	    {
	      cnt++;
	      dfs(j,i,l,r);
	    }
	}
      cout<<cnt<<endl;
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;

const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int main()
{
  ios_base::sync_with_stdio(false);

  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int vis[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
    }
  scanf("%d", &k);
  while(k--)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      cur=k+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int vis[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
    }
  scanf("%d", &k);
  for(int i=0;i<k;i++)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int maxN=510;
int vis[maxN],sz[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<sz[cnt];i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      cin>>u>>v;
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
      sz[u]++,sz[v]++;
    }
  cin>>k;
  for(int i=0;i<k;i++)
    {
      ans=0;
      cin>>l>>r;
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      cout<<ans<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,r,l,cur;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(root<l or root>r)
	{
	  if(vis[v]!=cur)
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      cur=i+1;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int vis[maxN],sz[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      cin>>u>>v;
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
      sz[u]++,sz[v]++;
    }
  scanf("%d", &k);
  for(int i=0;i<k;i++)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second

int n,m,k,r,l;
const int maxN=500+70;
int vis[maxN];
vector< pair<int,int> > G[maxN];
void dfs(int u,int cur)
{
  vis[u]=cur;
  for(int i;i<G[u].size();i++)
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(vis[v]!=cur and (root<l or root>r ))
	{
	  dfs(v,cur);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  for(int i=0;i<k;i++)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      for(int j=0;j<n;j++)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j,i+1);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

bool vis[500+70];
int n,m,k,sz[500+70],r,l;
const int maxN=500+70;
vector< pii > G[maxN];
inline void dfs(int u )
{
  vis[u]=true;
  LOOP(i, G[u].size())
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h;
      if(!vis[v] )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v);
	}
    }
}

int main()
{
  ios :: sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(!vis[j])
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<endl;
      memset(vis,0,sizeof vis);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,sz[500+70];
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u,int cur,int l,int r)
{
  vis[u].pb(cur);
  LOOP(i, sz[u] )
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=vis[v].back();
      if(h!=cur )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v,cur,l,r);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));
      sz[u]++;
      sz[v]++;
    }
  LOOP(i,j)
    {
      vis[i].pb(-1);
    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      int r,l;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  int h=vis[j].back();
	  if(h!=i)
	    {
	      cnt++;
	      dfs(j,i,l,r);
	    }
	}
      cout<<cnt<<endl;
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,sz[500+70],r,l;
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
inline void dfs(int )
{
  vis[u]=true;
  LOOP(i, sz[u] )
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(!vis[v] )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));
      sz[u]++;
      sz[v]++;
    }
  LOOP(i,n+1)
    {
      vis[i].pb(-1);
    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(!vis[i])
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<endl;
      memset(vis,0,sizeof vis);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,r,l,cur;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(root<l and root>r)
	{
	  if(vis[v]!=cur)
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      cur=i+1;
	      dfs(j);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

using namespace std;
#define mp make_pair
#define pb push_back

int n,m,k,r,l;
const int maxN=500+70;
int vis[maxN];
vector< pair<int,int> > G[maxN];
void dfs(int u,int cur)
{
  vis[u]=cur;
  for(int i;i<G[u].size();i++)
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      if(vis[v]!=cur and (root<l or root>r ))
	{
	  dfs(v,cur);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  for(int i=0;i<k;i++)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      for(int j=0;j<n;j++)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j,i+1);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

const int maxM=1e4+20;
const int maxN=500+19;
pair<int , int>  e[maxM];
int parent[maxN],rank[maxN],n,m,k;
vector<int> v,v1;
inline int Find(int x)
{
  if(parent[x]!=x)
    parent[x]=Find(parent[x]);
  return parent[x];
}
inline void Union(int x, int y)
{
 int xroot,yroot;
  xroot=Find(x);
  yroot=Find(y);
  if(xroot!=yroot)
    {
      if(rank[xroot]<rank[yroot])
	{
	  parent[xroot]=yroot;
	}
      else if(rank[xroot]>rank[yroot])
	{
	  parent[yroot]=xroot;
	}
      else
	{
	  parent[yroot]=xroot;
	  rank[xroot]=rank[xroot]+1;
	}
    }
}
void solve(int l,int r)
{
  for(int i=0;i<n;i++)
    {
      parent[i]=i;
      rank[i]=0;
    }
  int cnt=n;
  LOOP(i, Size( v))
    {
      if(v[i] < l)
	{
	  int c1,c2;
	  c1=Find(e[v[i]].X);c2=Find(e[v[i]].Y);
	  if(c1!=c2)
	    {
	      Union(e[v[i]].X,e[v[i]].Y);cnt--;
	    }
	}
     }
  LOOP(i, Size( v1))
    {
      if(v1[i] >r)
	{
	  int c1,c2;
	  c1=Find(e[v1[i]].X);c2=Find(e[v1[i]].Y);
	  if(c1!=c2)
	    {
	      Union(e[v1[i]].X,e[v1[i]].Y);cnt--;
	    }
	}
     }
  cout<<cnt<<'\n';
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  int r,l;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      e[i]=mp(u,v);
    }
  LOOP(i,n)
    {
      parent[i]=i;
    }
  LOOP(i,m)
    {
      int c1=Find(e[i].X);
      int c2=Find(e[i].Y);
      if(c1!=c2)
	{
	  v.pb(i);
	  Union(e[i].X,e[i].Y);
	}
    }
 LOOP(i,n)
    {
      parent[i]=i;
    }
 for(int i=n-1;i>-1;i--)
   {
     int c1,c2;
     c1=Find(e[i].X);
     c2=Find(e[i].Y);
     if(c1!=c2)
       {
	 v1.pb(i);
	 Union(e[i].X,e[i].Y);
       }
   }
  cin>>k;
  LOOP(i,k)
    {
      cin>>l>>r;
      l--,r--;
      solve(l,r);
    }
  return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 505;

int n, m;
vector <ii> neigh[Maxn];
int k;
int l, r;
bool taken[Maxn];
int res;

void Traverse(int v)
{
    taken[v] = true;
    for (int i = 0; i < neigh[v].size(); i++) {
        ii u = neigh[v][i];
        if ((u.second < l || u.second > r) && !taken[u.first])
            Traverse(u.first);
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(ii(b, i)); neigh[b].push_back(ii(a, i));
    }
    scanf("%d", &k);
    while (k--) {
        scanf("%d %d", &l, &r);
        fill(taken + 1, taken + n + 1, false);
        res = 0;
        for (int i = 1; i <= n; i++) if (!taken[i]) {
            res++; Traverse(i);
        }
        printf("%d\n", res);
    }
    return 0;
}


//In the name of God
#include <algorithm>
#include <iostream>
#include <cassert>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define X first
#define Y second
//#define X imag()
//#define Y real()
//#define cin fin
//#define cout fout

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;

#define top() front()

int n, m, L, R, k;
vector<pii> g[600];
bool vis[600];
int sz[600];
inline void DFS (int v)
{
  vis[v] = 1;
  for(int i = 0 ; i < sz[v] ; i++)
    if(!vis[g[v][i].X] && (g[v][i].Y < L || g[v][i].Y > R))
      DFS(g[v][i].X);
}

int main ()
{
  ios :: sync_with_stdio(0);
  cin >> n >> m ;
  for(int u, v, i = 0 ; i < m ; i++)
    {
      cin >> u >> v ;
      g[u].push_back(pii(v, i + 1));
      g[v].push_back(pii(u, i + 1));
      sz[u]++,sz[v]++;
    }
  cin >> k ;
  for(int i = 0 ; i < k ; i++)
    {
      cin >> L >> R ;
      int ans = 0;
      memset(vis, 0, sizeof vis);
      for(int i = 1 ; i <= n ; i++)
	if(!vis[i])
	  {
	    DFS(i);
	    ans ++;
	  }
      cout << ans << endl ;
    }

}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k;
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
void dfs(int u,int cur,int l,int r)
{
  vis[u].pb(cur);
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=-1;
      if( Size( vis[v])!=0)
	h=vis[v].back();
      if(h!=cur )
	{
	  if(root>=l and root<=r)
	    int h;
	  else
	    dfs(v,cur,l,r);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      int r,l;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  int h=-1;
	  if(Size ( vis[j])!=0)
	    h=vis[j].back();
	  if(h!=i)
	    {
	      cnt++;
	      dfs(j,i,l,r);
	    }
	}
      cout<<cnt<<endl;
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int vis[maxN],sz[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
      sz[u]++,sz[v]++;
    }
  scanf("%d", &k);
  for(int i=0;i<k;i++)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;
bool vis[500+70];
int n,m,k,sz[500+70],r,l;
const int maxN=500+70;
vector< pii > G[maxN];
inline void dfs(int u )
{
  vis[u]=true;
  LOOP(i, sz[u] )
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h;
      if(!vis[v] )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));
      sz[u]++;
      sz[v]++;
    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(!vis[j])
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<endl;
      memset(vis,0,sizeof vis);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int vis[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
    }
  scanf("%d", &k);
  while(k--)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int maxN=510;
int vis[maxN],sz[maxN],u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<sz[cnt];i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      cin>>u>>v;
      G[u].push_back(make_pair(v,i));
      G[v].push_back(make_pair(u,i));
      sz[u]++,sz[v]++;
    }
  cin>>k;
  for(int i=0;i<k;i++)
    {
      ans=0;
      cin>>l>>r;
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      cout<<ans<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k;
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u,int cur,int l,int r)
{
  vis[u].pb(cur);
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=-1;
      if( Size( vis[v])!=0)
	h=vis[v].back();
      if(h!=cur )
	{
	  if(root>=l and root<=r)
	    int h;
	  else
	    dfs(v,cur,l,r);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      int r,l;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  int h=-1;
	  if(Size ( vis[j])!=0)
	    h=vis[j].back();
	  if(h!=i)
	    {
	      cnt++;
	      dfs(j,i,l,r);
	    }
	}
      cout<<cnt<<endl;
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,sz[500+70],r,l;
const int maxN=500+70;
vector<int> vis[maxN];
vector< pii > G[maxN];
inline void dfs(int u )
{
  vis[u]=true;
  LOOP(i, sz[u] )
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h;
      if(!vis[v] )
	{
	  if(root>=l && root<=r)
	    h;
	  else
	    dfs(v);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));
      sz[u]++;
      sz[v]++;
    }
  LOOP(i,n+1)
    {
      vis[i].pb(-1);
    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(!vis[i])
	    {
	      cnt++;
	      dfs(j);
	    }
	}
      cout<<cnt<<endl;
      memset(vis,0,sizeof vis);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>

const int maxN=510;
int vis[maxN],sz[maxN],u,v,r,l,cur,ans=0;
vector< pair< int , int > > G[maxN];

void dfs(int cnt)
{
  vis[cnt]=cur;
  for(int i=0;i<sz[cnt];i++)
    {
      if(vis[G[cnt][i].first]!=cur and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  ios::sync_with_stdio(0);
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      cin>>u>>v;
      G[u].push_back(make_pair(v,i));
      G[v].push_back(make_pair(u,i));
      sz[u]++,sz[v]++;
    }
  cin>>k;
  for(int i=0;i<k;i++)
    {
      ans=0;
      cin>>l>>r;
      cur=i+1;
      for(int j=1;j<n+1;j++)
	{
	  if(vis[j]!=cur)
	    {
	      ans++;
	      dfs(j);
	    }
	}
      cout<<ans<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,r,l;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
void dfs(int u,int cur)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=-1;
      if(vis[v]!=cur )
	{
	  if(root>=l and root<=r)
	    h;
	  else
	    dfs(v,cur);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j,i+1);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
void dfs(int u,int cur,int l,int r)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=-1;
      if(vis[v]!=cur )
	{
	  if(root>=l and root<=r)
	    int h;
	  else
	    dfs(v,cur,l,r);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      int r,l;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j,i+1,l,r);
	    }
	}
      cout<<cnt<<endl;
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=504;
int u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];
bool vis[maxN];
void dfs(int cnt)
{
  vis[cnt]=true;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(!vis[G[cnt][i].first])
	{
	  if(G[cnt][i].second>r or G[cnt][i].second<l)
	    dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(pair<int , int> (v,i+1));
      G[v].push_back(pair<int , int> (u,i+1));
    }
  scanf("%d", &k);
  while(k--)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      fill(vis+1,vis+n+1,false);
      for(int j=1;j<n+1;j++)
	{
	  if(!vis[j])
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=510;
int u,v,r,l,cur,ans=0,n,m,k;
vector< pair< int , int > > G[maxN];
bool vis[maxN];
void dfs(int cnt)
{
  vis[cnt]=true;
  for(int i=0;i<G[cnt].size();i++)
    {
      if(!vis[G[cnt][i].first] and (G[cnt][i].second>r or G[cnt][i].second<l))
	{
	  dfs(G[cnt][i].first);
	}
    }

}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++)
    {
      scanf("%d %d",&u,&v);
      G[u].push_back(make_pair(v,i+1));
      G[v].push_back(make_pair(u,i+1));
    }
  scanf("%d", &k);
  while(k--)
    {
      ans=0;
      scanf("%d %d",&l,&r);
      fill(vis+1,vis+n+1,false);
      for(int j=1;j<n+1;j++)
	{
	  if(!vis[j])
	    {
	      ans++;
	      dfs(j);
	    }
	}
      printf("%d\n", ans);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

const int maxM=1e4+20;
const int maxN=500+19;
pair<int , int>  e[maxM];
int parent[maxN],rank[maxN],n,m,k;

inline int Find(int x)
{
  if(parent[x]!=x)
    parent[x]=Find(parent[x]);
  return parent[x];
}
inline void Union(int x, int y)
{
  int xroot,yroot;
  xroot=Find(x);
  yroot=Find(y);
  parent[xroot]=yroot;
}
void solve(int l,int r)
{
  for(int i=0;i<n;i++)
    {
      parent[i]=i;
      rank[i]=0;
    }
  int cnt=n;
  LOOP(i,m)
    {
      if(i>r or i<l)
	{
	  int c1,c2;
	  c1=Find(e[i].X);c2=Find(e[i].Y);
	  if(c1!=c2)
	    {
	      Union(e[i].X,e[i].Y);cnt--;
	    }
	}
     }
  cout<<cnt<<'\n';
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  int r,l;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      e[i]=mp(u,v);
    }
  cin>>k;
  LOOP(i,k)
    {
      cin>>l>>r;
      l--,r--;
      solve(l,r);
    }
  return 0;
}


/* In the name of Allah
   Ramin Zarifi(RamiZ)*/

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <list>

#define pb push_back
#define mp make_pair
#define pf push_front
#define popb pop_back
#define popf pop_front
#define In insert
#define X first
#define Y second

#define FOR( i , a , n ) for(int (i)=(a);(i)<int(n);++(i))
#define LOOP( i , n ) for(int (i)=0;(i)<int (n);++(i))
#define Size( n )  (int)(n).size()
#define OUT( n ) cout<<fixed<<setprecision(15)<<(n)

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL>  pLL;
typedef string str;
typedef vector<int> VI;
const LD PI=LD(3.14159265358979);
const LD eps=1e-7;
const LL inf=1e18;

int n,m,k,r,l;
const int maxN=500+70;
int vis[maxN];
vector< pii > G[maxN];
void dfs(int u,int cur)
{
  vis[u]=cur;
  LOOP(i, Size( G[u]))
    {
      int v=G[u][i].X;
      int root=G[u][i].Y;
      int h=-1;
      if(vis[v]!=cur )
	{
	  if(root>=l and root<=r)
	    int h;
	  else
	    dfs(v,cur);
	}
    }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin>>n>>m;
  LOOP(i,m)
    {
      int u,v;
      cin>>u>>v;
      u--,v--;
      G[u].pb(mp(v,i));
      G[v].pb(mp(u,i));

    }
  cin>>k;
  LOOP(i,k)
    {
      int cnt=0;
      cin>>l>>r;
      r--,l--;
      LOOP(j,n)
	{
	  if(vis[j]!=i+1)
	    {
	      cnt++;
	      dfs(j,i+1);
	    }
	}
      cout<<cnt<<'\n';
    }
  return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int calc(){
    int s=0;
    for(int i=1;i<=n;++i)if(par[i]==i)++s;
    return s;
}
int x[10002],y[10002];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    scanf("%d",&k);
    int s,e,A,B;
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        scanf("%d%d",&s,&e);
        if(s>e){
            int t=s;
            s=e;
            e=t;
        }
        for(int i=1;i<=m;++i){
            if(i>=s && i<=e)continue;
            A=find(x[i]);
            B=find(y[i]);
            if(A!=B)par[A]=B;
        }
        printf("%d\n",calc());
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int x[10002],y[10002];
int s,e,A,B;
int main(){
    vector<int>v1,v2;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=1;i<=m;++i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v1.push_back(i);
        }
    }
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=m;i>=1;--i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v2.push_back(i);
        }
    }
    scanf("%d",&k);
    int sz,idx;
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        sz=n;
        scanf("%d%d",&s,&e);
        idx=0;
        while(v1[idx]<s){
            A=find(x[v1[idx]]);
            B=find(y[v1[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            ++idx;
        }
        idx=0;
        while(v2[idx]>e){
            A=find(x[v2[idx]]);
            B=find(y[v2[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            ++idx;
        }
        cout<<sz<<endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int x[10002],y[10002];
int s,e,A,B;
int main(){
	vector<int>v1,v2;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=1;i<=m;++i){
    	A=find(x[i]);
       	B=find(y[i]);
       	if(A!=B){
       		par[A]=B;
       		v1.push_back(i);
       	}
    }
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=m;i>=1;--i){
    	A=find(x[i]);
       	B=find(y[i]);
       	if(A!=B){
       		par[A]=B;
       		v2.push_back(i);
       	}
    }
    reverse(v2.begin(),v2.end());
    scanf("%d",&k);
    int sz,idx;
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        sz=n;
        scanf("%d%d",&s,&e);
        idx=0;
        while(v1[idx]<s){
        	A=find(x[v1[idx]]);
        	B=find(y[v1[idx]]);
        	if(A!=B){
        		par[A]=B;
        		--sz;
        	}
        	++idx;
        }
        idx=v2.size();
        --idx;
        while(v2[idx]>e){
        	A=find(x[v2[idx]]);
        	B=find(y[v2[idx]]);
        	if(A!=B){
        		par[A]=B;
        		--sz;
        	}
        	--idx;
        }
       	cout<<sz<<endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int x[10002],y[10002];
int s,e,A,B;
int main(){
    vector<int>v1,v2;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=1;i<=m;++i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v1.push_back(i);
        }
    }
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=m;i>=1;--i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v2.push_back(i);
        }
    }
    scanf("%d",&k);
    int sz,idx;
    int limit=v1.size();
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        sz=n;
        scanf("%d%d",&s,&e);
        idx=0;
        while(v1[idx]<s && idx<limit){
            A=find(x[v1[idx]]);
            B=find(y[v1[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            ++idx;
        }
        idx=0;
        while(v2[idx]>e && idx<limit){
            A=find(x[v2[idx]]);
            B=find(y[v2[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            ++idx;
        }
        cout<<sz<<endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int x[10002],y[10002];
int s,e,A,B;
int main(){
    vector<int>v1,v2;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=1;i<=m;++i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v1.push_back(i);
        }
    }
    for(int i=1;i<=n;++i)par[i]=i;
    for(int i=m;i>=1;--i){
        A=find(x[i]);
        B=find(y[i]);
        if(A!=B){
            par[A]=B;
            v2.push_back(i);
        }
    }
    reverse(v2.begin(),v2.end());
    scanf("%d",&k);
    int sz,idx;
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        sz=n;
        scanf("%d%d",&s,&e);
        idx=0;
        while(v1[idx]<s){
            A=find(x[v1[idx]]);
            B=find(y[v1[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            ++idx;
        }
        idx=v2.size();
        --idx;
        while(v2[idx]>e){
            A=find(x[v2[idx]]);
            B=find(y[v2[idx]]);
            if(A!=B){
                par[A]=B;
                --sz;
            }
            --idx;
        }
        cout<<sz<<endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<stdio.h>
#include<map>
#include<set>
#include<memory.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,par[502];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
int calc(){
    int s=0;
    for(int i=1;i<=n;++i)if(par[i]==i)++s;
    return s;
}
int x[10002],y[10002];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
        scanf("%d%d",&x[i],&y[i]);
    scanf("%d",&k);
    int s,e;
    for(int j=0;j<k;++j){
        for(int i=1;i<=n;++i)par[i]=i;
        scanf("%d%d",&s,&e);
        if(s>e){
            int t=s;
            s=e;
            e=t;
        }
        for(int i=1;i<=m;++i){
            if(i>=s && i<=e)continue;
            int A=find(x[i]);
            int B=find(y[i]);
            if(A!=B)par[A]=B;
        }
        cout<<calc()<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>

bool vis[504];

using namespace std;

vector<int> v[505], vv[505];

void dfs(int pos, int l, int r)
{
        vis[pos] = 1;
        for(int i = 0; i < v[pos].size(); i++) {
            if(vis[v[pos][i]]) continue;
            if(vv[pos][i] >= l && vv[pos][i] <= r) continue;
            dfs(v[pos][i], l, r);
        }
}

int main()
{
    int n, m, x, y;

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        scanf("%d%d", &x, &y);
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
        vv[x-1].push_back(i+1);
        vv[y-1].push_back(i+1);
    }

    int k;

    cin >> k;
    map<pair<int, int>, int> mm;
    for(int i = 0; i < k; i++) {
        scanf("%d%d", &x, &y);
        int ans = 0;
        if(mm[pair<int, int>(x, y)]) {
            printf("%d\n", mm[pair<int, int>(x, y)]);
            continue;
        }
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < n; i++) {
            if(!vis[i]) {
                dfs(i, x, y);
                ans++;
            }
        }
        printf("%d\n", ans);
        mm[pair<int, int>(x, y)] = ans;
    }
}


#include <iostream>
#include <cstdio>

using namespace std;

int p[10004];
int pre[10004];
int suf[10004];
int x[10004];
int y[10004];

int get(int pos)
{
        if(p[pos] == pos) return pos;
        else return get(p[pos]);
}

int main()
{
    int n, m;
    ios_base::sync_with_stdio(false);
    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
    }

    for(int i = 0; i < n; i++) p[i] = i;

    int v1, v2;
    v1 = v2 = 0;

    for(int i = 0; i < m; i++) {
        int p1, p2;
        p1 = get(x[i]);
        p2 = get(y[i]);
        if(p1 != p2) {
            p[p1] = p2;
            pre[v1++] = i;
        }
    }

    for(int i = 0; i < n; i++) p[i] = i;

    for(int i = m-1; i >= 0; i--) {
        int p1, p2;
        p1 = get(x[i]);
        p2 = get(y[i]);
        if(p1 != p2) {
            p[p1] = p2;
            suf[v2++] = i;
        }
    }

    int k;

    cin >> k;

    for(int i = 0; i < k; i++) {
        int l, r;

        cin >> l >> r;
        l--, r--;

        for(int i = 0; i < n; i++) p[i] = i;

        for(int i = 0; i < v1; i++) {
            if(pre[i] < l) {
                int p1, p2;
                p1 = get(x[pre[i]]);
                p2 = get(y[pre[i]]);
                if(p1 != p2) {
                    p[p1] = p2;
                }
            }
        }

        for(int i = 0; i < v2; i++) {
            if(suf[i] > r) {
                int p1, p2;
                p1 = get(x[suf[i]]);
                p2 = get(y[suf[i]]);
                if(p1 != p2) {
                    p[p1] = p2;
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            if(p[i] == i) ans++;
        }

        cout << ans << endl;
    }
}


#include <iostream>
#include <cstdio>

using namespace std;

int p[10004];
int pre[10004];
int suf[10004];
int x[10004];
int y[10004];
int rank[10004];

int get(int pos)
{
        if(p[pos] == pos) return pos;
        else return get(p[pos]);
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i++) {
        scanf("%d%d", &x[i], &y[i]);
    }

    for(int i = 0; i < n; i++) p[i] = i, rank[i] = 0;

    int v1, v2;
    v1 = v2 = 0;

    for(int i = 0; i < m; i++) {
        int p1, p2;
        p1 = get(x[i]);
        p2 = get(y[i]);
        if(p1 != p2) {
            if(rank[p1] == rank[p2]) rank[p1]++;
            if(rank[p1] < rank[p2])
                p[p1] = p2;
            else p[p2] = p1;
            pre[v1++] = i;
        }
    }

    for(int i = 0; i < n; i++) p[i] = i, rank[i] = 0;

    for(int i = m-1; i >= 0; i--) {
        int p1, p2;
        p1 = get(x[i]);
        p2 = get(y[i]);
        if(p1 != p2) {
            if(rank[p1] == rank[p2]) rank[p1]++;
            if(rank[p1] < rank[p2])
                p[p1] = p2;
            else p[p2] = p1;
            suf[v2++] = i;
        }
    }

    int k;

    cin >> k;

    for(int i = 0; i < k; i++) {
        int l, r;

        scanf("%d%d", &l, &r);
        l--, r--;

        for(int i = 0; i < n; i++) p[i] = i, rank[i] = 0;

        for(int i = 0; i < v1; i++) {
            if(pre[i] < l) {
                int p1, p2;
                p1 = get(x[pre[i]]);
                p2 = get(y[pre[i]]);
                if(p1 != p2) {
                    if(rank[p1] == rank[p2]) rank[p1]++;
                    if(rank[p1] < rank[p2])
                        p[p1] = p2;
                    else p[p2] = p1;
                }
            }
            else break;
        }

        for(int i = 0; i < v2; i++) {
            if(suf[i] > r) {
                int p1, p2;
                p1 = get(x[suf[i]]);
                p2 = get(y[suf[i]]);
                if(p1 != p2) {
                    if(rank[p1] == rank[p2]) rank[p1]++;
                    if(rank[p1] < rank[p2])
                        p[p1] = p2;
                    else p[p2] = p1;
                }
            }
            else break;
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            if(p[i] == i) ans++;
        }

        printf("%d\n", ans);
    }
}


#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>

bool vis[10004];

using namespace std;

vector<int> v[10005], vv[10005];

void dfs(int pos, int l, int r)
{
        vis[pos] = 1;
        for(int i = 0; i < v[pos].size(); i++) {
            if(vis[v[pos][i]]) continue;
            if(vv[pos][i] >= l && vv[pos][i] <= r) continue;
            dfs(v[pos][i], l, r);
        }
}

int main()
{
    //ios_base::sync_with_stdio(false);
    int n, m, x, y;

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> x >> y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
        vv[x-1].push_back(i+1);
        vv[y-1].push_back(i+1);
    }

    int k;

    cin >> k;
    map<pair<int, int>, int> mm;
    for(int i = 0; i < k; i++) {
        scanf("%d%d", &x, &y);
        int ans = 0;
        if(mm[pair<int, int>(x, y)]) {
            cout << mm[pair<int, int>(x, y)] << endl;
        }
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < n; i++) {
            if(!vis[i]) {
                dfs(i, x, y);
                ans++;
            }
        }
        printf("%d\n", ans);
        mm[pair<int, int>(x, y)] = ans;
    }
}