import java.util.*;
class Solution {
public String solution(String[] cards1, String[] cards2, String[] goal) {
Queue<String> queue1 = new LinkedList<>();
Queue<String> queue2 = new LinkedList<>();
for(String x: cards1){
queue1.add(x);
}
for(String x: cards2){
queue2.add(x);
}
for(int i=0; i<goal.length; i++){
String a = queue1.peek();
String b = queue2.peek();
if(a != null && a.equals(goal[i])){
queue1.poll();
}else if(b != null && b.equals(goal[i])){
queue2.poll();
}else{
return "No";
}
}
return "Yes";
}
}