#include <stdio.h>

int main(){
    int input,j,k,sum;
    scanf("%d",&k);
    while(k--){
        scanf("%d",&input);
        while(input!=0){
            j=input%10;
            sum=sum+j;
            input=input/10;
        }
        printf("%d\n",sum);
        sum=0;
    }
    return 0;
}