```java
public static boolean check(StringBuffer x, StringBuffer y){
int n = x.length(),m = y.length();
int k = Math.max(n,m);
for(int i=0;i<k;i++){
if(x.charAt(i%n)<y.charAt(i%m))
return true;
if(x.charAt(i%n)>y.charAt(i%m))
return false;
}
return true;
}
```