import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @solution : Bestcoder Pro.ID 2017 字符串统计
* @discription : 对于给定的一个字符串,统计其中数字字符出现的次数。
* @input : 输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。
* @output : 对于每个测试实例,输出该串中数值的个数,每个输出占一行。
*
* @file com.acmcoder.acm.ProblemID2017.Main.java
* @author wuyanhui
* @version Apr 22, 2016 -- 8:40:37 PM
*
* @PS :
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
Pattern p = Pattern.compile("\\D");
while (in.hasNext()) {
n = Integer.valueOf(in.nextLine());
for (int i = 0; i < n; i++) {
String s = in.nextLine();
Matcher m = p.matcher(s);
String newS = m.replaceAll("");
System.out.println(newS.length());
}
}
in.close();
}
}