• Source
    1. import java.io.*;
    2. class ISSNAKE
    3. {
    4. static BufferedReader xy=new BufferedReader(new InputStreamReader(System.in));
    5. static int r=0;
    6. static int n=0;
    7. static char ar[][];
    8. static int x=0;static int y=0;
    9. static int p=-1;static int q=-1;
    10. public static void main(String args[])throws IOException
    11. {
    12. r=Integer.parseInt(xy.readLine());
    13. for(int i=0;i<r;i++)
    14. {
    15. daff();
    16. }
    17. }
    18.  
    19. public static void input()throws IOException
    20. {
    21. n=Integer.parseInt(xy.readLine());
    22. ar=new char[2][n];
    23. String s=xy.readLine();
    24. for(int i=0;i<n;i++)
    25. ar[0][i]=s.charAt(i);
    26. s=xy.readLine();
    27. for(int i=0;i<n;i++)
    28. ar[1][i]=s.charAt(i);
    29. }
    30.  
    31. static void find()
    32. {
    33. for(int i=0;i<2;i++)
    34. {
    35. for(int j=0;j<n;j++)
    36. {
    37. if (ar[i][j]=='#')
    38. {
    39. x=i;
    40. y=j;
    41. if(i==0&&ar[1][j]=='#')
    42. {
    43. p=1;
    44. q=j;
    45. }
    46. return;
    47. }
    48. }
    49. }
    50. }
    51.  
    52. static void kill(char arr[][],int a,int b)
    53. {
    54. arr[a][b]='.';
    55. try
    56. {
    57. if(a==0&& arr[a+1][b]=='#')
    58. kill (arr,a+1,b);
    59. else if(a==1&& arr[a-1][b]=='#')
    60. kill (arr,a-1,b);
    61. else if (arr[a][b+1]=='#')
    62. kill (arr,a,b+1);
    63. }
    64. catch(Exception e)
    65. {
    66. }
    67. }
    68.  
    69. static boolean check(char arr[][])
    70. {
    71. for(int i=0;i<2;i++)
    72. {
    73. for(int j=0;j<n;j++)
    74. {
    75. if (arr[i][j]=='#')
    76. {
    77. return false;
    78. }
    79. }
    80. }
    81. return true;
    82. }
    83.  
    84. public static void daff()throws IOException
    85. {
    86.  
    87. input();
    88. find();
    89.  
    90. if(p==-1)
    91. {
    92. kill(ar,x,y);
    93. if(check(ar))
    94. System.out.println("yes");
    95. else
    96. System.out.println("no");
    97. }
    98.  
    99. if(p!=-1)
    100. {
    101. char newar[][]=new char[2][n];
    102. for(int i=0;i<2;i++)
    103. {
    104. for(int j=0;j<n;j++)
    105. {
    106. newar[i][j]=ar[i][j];
    107. }
    108. }
    109.  
    110. kill(ar,x,y);
    111. boolean flag=check(ar);
    112. if(flag==true)
    113. {
    114. System.out.println("yes");
    115. return;
    116. }
    117. else
    118. {
    119. kill(newar,p,q);
    120. if(check(newar))
    121. System.out.println("yes");
    122. else
    123. System.out.println("no");
    124. }
    125. }
    126.  
    127. }
    128. }
    129.