import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] argv) throws Exception {
    Matcher m = Pattern.compile("(?:^|(?<=\\s))(?=((?:\\S+\\s+){2}\\S+)(?=\\s|$))")
      .matcher("word1 word2 word3 word4 word6 word6");
    while (m.find()) {
      System.out.println(m.group(1));
    }
  }
}