/* @JUDGE_ID:  34406YP  100 Java */

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

class Hardware {

  public static void main(String[] args) {
    Hardware myWork = new Hardware();
	myWork.begin();
  }

  int[] tab;
  int num_digits;

  void begin () {

      String s = readLn(255);
	  StringTokenizer st = new StringTokenizer(s);
	  int rep = Integer.parseInt(st.nextToken());

      s = readLn(255);
      for(int i=0;i<rep;i++) { 
        System.out.println(s);
        s = readLn(255);
		System.out.println(s);
	  
	    tab = new int[10];
		num_digits = 0;

        s = readLn(255);
		while (s != null && fortsett(s.charAt(0))) {
		  if (s.charAt(0) != '+')
		    legg_til(s);
		  else {
		    s = s.substring(1,s.length());
			st = new StringTokenizer(s);
			int start = Integer.parseInt(st.nextToken());
			int slutt = Integer.parseInt(st.nextToken());
			int hopp = Integer.parseInt(st.nextToken());
			for(int k=start;k<=slutt;k+=hopp)
			  legg_til(Integer.toString(k));
	      }

          s = readLn(255);
		} // while
        for(int k=0;k<10;k++) 
            System.out.println("Make "+tab[k]+" digit "+k);
        if (num_digits!=1)
            System.out.println("In total "+num_digits+" digits");
        else
            System.out.println("In total "+num_digits+" digit");
	    
      } // rep

  } // void begin

  void legg_til(String s) {

    s = s.trim();
	for(int i=0;i<s.length();i++) {
      char c = s.charAt(i);
	  tab[c-'0']++;
	  num_digits++;
	}

  }

  boolean fortsett(char c) {
    if (c == '+')
	  return true;
    if (c <= '9' && c >= '0')
	  return true;
	return false;
  }
												 
  static String readLn (int maxLg) {
    byte lin[] = new byte [maxLg];
	int lg = 0, car = -1;
	String line = "";
			   
	try {
	  while (lg < maxLg) {
	    car = System.in.read();
	    if ((car < 0) || (car == '\n')) break;
		lin [lg++] += car;
	  }
	}
	catch (IOException e) { return (null); }
	
    if ((car < 0) && (lg == 0)) return (null);
	return (new String (lin, 0, lg));
  }
}
