

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
char [][]graph = new char[n][n];
for(int i=0;i<n;i++)
graph[i] = sc.nextLine().toCharArray();
int m = sc.nextInt();
int [][]query = new int[m][4];
for(int i=0;i<m;i++){
for(int j=0;j<4;j++){
query[i][j] = sc.nextInt();
}
}
for(int i=0;i<m;i++){
boolean ok = check(graph,new int[n][n],query[i]);
System.out.println(ok);
}
}
private static boolean check(char[][] graph, int[][] lable, int[] points) {
int x1 = points[0];
int y1 = points[1];
int x2 = points[2];
int y2 = points[3];
if(x1 == x2 && y1 == y2)
return true;
int value = graph[x1][y1];
boolean f1 = false;
boolean f2 = false;
boolean f3 = false;
boolean f4 = false;
if(y1-1 >=0 && lable[x1][y1-1] == 0 && graph[x1][y1-1] == value ){
lable[x1][y1-1] = 1;
points[1] = y1-1;
f1 = check(graph,lable,points);
lable[x1][y1-1] = 0;
points[1] = y1;
}
if(y1+1 < graph.length && lable[x1][y1+1] == 0 && graph[x1][y1+1] == value){
lable[x1][y1+1] = 1;
points[1] = y1+1;
f2 = check(graph,lable,points);
lable[x1][y1+1] = 0;
points[1] = y1;
}
if(x1+1 < graph.length && lable[x1+1][y1] == 0 && graph[x1+1][y1] == value ){
lable[x1+1][y1] = 1;
points[0] = x1+1;
f3 = check(graph,lable,points);
lable[x1+1][y1] = 0;
points[0] = x1;
}
if(x1-1 >=0 && lable[x1-1][y1] == 0 && graph[x1-1][y1] == value ){
lable[x1-1][y1] = 1;
points[0] = x1-1;
f4 = check(graph,lable,points);
lable[x1-1][y1] = 0;
points[0] = x1;
}
return f1 || f2 || f3 || f4;
}
}