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

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

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner input=new Scanner(System.in);
        String text;
        String cha;

        System.out.println("Enter a Serial number: ");
        text=input.nextLine();

        if(text.matches("[A-Za-z0-9]+(-[A-Za-z0-9]+){2}")){
            System.out.println("Serial number "+text+" verification \nValid");
            System.out.println("Enter a wildchar character: ");
            cha=input.nextLine();
            text= text.replaceAll("[A-Za-z0-9]", cha);
            System.out.println("Masked serial: "+text);
        } else if(text.matches(".*[^-A-Za-z0-9].*")) {
            System.out.println("Invalid. Serial should only contain letters, numbers, and dashes(-)");
        } else if(text.matches("[A-Za-z0-9]+(-+[A-Za-z0-9]+){2,}")) {
            System.out.println("Invalid. There should be exactly 2 non-consecutive dashes in the middle. ");
        }
	}
}