//https://www.hackerrank.com/challenges/two-strings
import java.io.*;

public class Solution {
    public static void main(String[] args) throws IOException{
        StringBuffer sb = new StringBuffer();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        //For each test case
        for(byte T = Byte.parseByte(br.readLine()); T > 0; --T){
            
            //Get strings
            final char[] A = br.readLine().toCharArray();
            final char[] B = br.readLine().toCharArray();
            
            //Check if both strings share a common substring
            sb.append(hasSubstring(A, B) ? "YES\n" : "NO\n");
        }
        System.out.print(sb);
    }
    
    private static boolean hasSubstring(final char[] A, final char[] B){
        
        //Get presence of letters in string A
        int bitsA = 0;
        for(int i = 0, n = A.length; i < n; bitsA |= 1 << (A[i++] - 'a')){}
        
        //Get presence of letters in string B
        int bitsB = 0;
        for(int i = 0, n = B.length; i < n; bitsB |= 1 << (B[i++] - 'a')){}
        
        //Check if both strings have any letters in common
        return (bitsA & bitsB) != 0;
    }
}

@@ -88,18 +88,16 @@
 ution %7B%0A
-  
   public
@@ -149,20 +149,16 @@
 eption%7B%0A
-    
     Stri
@@ -195,20 +195,16 @@
 ();%0A    
-  
-  
 Buffered
@@ -273,29 +273,21 @@
 ));%0A    
-    %0A  
+%0A
     
-  
 //For ea
@@ -299,20 +299,16 @@
 st case%0A
-    
     for(
@@ -366,35 +366,23 @@
 %7B%0A      
-      %0A   
+%0A
       
-   
 //Get st
@@ -389,30 +389,24 @@
 rings%0A      
-     
- 
 final char%5B%5D
@@ -445,22 +445,16 @@
 ;%0A      
-   
-   
 final ch
@@ -497,29 +497,17 @@
 ;%0A      
- 
-     %0A      
+%0A
       //
@@ -559,22 +559,16 @@
 g%0A      
-    
-  
 sb.appen
@@ -613,26 +613,18 @@
 %22);%0A    
-    %7D%0A    
+%7D%0A
     Syst
@@ -645,21 +645,15 @@
 b);%0A
-  
   %7D%0A  
- 
- %0A  
+%0A
   pr
@@ -719,33 +719,25 @@
 r%5B%5D B)%7B%0A    
-    %0A    
+%0A
     //Get pr
@@ -766,20 +766,16 @@
 tring A%0A
-    
     int 
@@ -781,36 +781,32 @@
  bitsA = 0;%0A    
-   
- 
 for(int i = 0, n
@@ -861,29 +861,21 @@
 )%7B%7D%0A    
-    %0A   
+%0A
     
- 
 //Get pr
@@ -904,20 +904,16 @@
 tring B%0A
-    
     int 
@@ -927,20 +927,16 @@
  0;%0A    
-   
- 
 for(int 
@@ -1003,21 +1003,13 @@
     
-    %0A   
+%0A
     
- 
 //Ch
@@ -1055,20 +1055,16 @@
  common%0A
-    
     retu
@@ -1088,16 +1088,14 @@
 ) != 0;%0A
-  
   %7D%0A%7D%0A

Update two-strings.java