/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
			// your code goes here
		Pattern p = Pattern.compile("^(_\\w*)|(\\w*_{2,}+\\w*)|(\\w*_$)");
		Matcher m = p.matcher("test_test_test");
		System.out.println("Is string invalid: "+ m.matches());
		
		
		 m = p.matcher("test_");
		System.out.println("Is string invalid: "+ m.matches());
		
		
		 m = p.matcher("test_____test");
		System.out.println("Is string invalid: "+ m.matches());
	}
}