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

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

/* 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
	{
	 String initial[] = {"djsndni123412ndksnd3412*&^%34(*(*1234"
		,"djsndni123412ndksnd3412*&^%34(*(*123"};
// remove all non-digits characters
	System.out.println(formatCardInput(initial[0].replaceAll("\\D", "")));
	System.out.println(formatCardInput(initial[1].replaceAll("\\D", "")));
	}
	private static String formatCardInput(String s){
		StringBuilder sb = new StringBuilder(s);
		System.out.println(sb);
		if(sb.length() == 16){
			int gap = 0;
			for (int i = 4; i< sb.length()-1;i+=4){
				sb.insert(i + gap,' ');
				gap++;
			}
		}
		else{
			sb.insert(4,' ');
			sb.insert(11,' ');
		}
	return sb.toString();
	}
}