#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << ", "
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

ll arr[maxn] , sum[maxn];
int flag[maxn];
int main()
{
    ll n,k;
    ll pp[64];
    int len = 0;
    cin>>n>>k;

    rep(i,1,n+1) cin>>arr[i];

    if(k==1){
        ll ans = 0;
        rep(i,1,n+1) if(arr[i]==1) ans++;
        cout<<ans<<endl;
        return 0;
    }
    if(k==-1){
        ll ans = 0;
        rep(i,1,n+1) if(arr[i]==1||arr[i]==-1) ans++;
        cout<<ans<<endl;
        return 0;
    }

    rep(i,1,64){
        pp[i] = pow(k,i);
        if(pp[i]>100000000000005||pp[i]<-100000000000005) break;
        len++;
    }

    rep(i,1,n+1) sum[i] = sum[i-1]+arr[i];

    map<ll,int> mymap;
    ll ans = 0;
    rep(i,1,n+1) if(arr[i]==1) ans++;

    mymap[0] = 1;
    rep(i,1,n+1){
        rep(j,1,len+1){
            ll tmp = sum[i]-pp[j];
            if(arr[i]==0&&tmp==0) continue;
            if(mymap.count(tmp)){
                //dd(i);dd(j);dd(tmp);de(mymap[tmp]);
                ans+=mymap[tmp];
            }
        }
        mymap[sum[i]]++;
    }
    cout<<ans<<endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << ", "
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

ll arr[maxn] , sum[maxn];
int flag[maxn];
int main()
{
    ll n,k;
    ll pp[64];
    int len = 0;
    //scanf("%lld%lld",&n,&k);
    cin>>n>>k;
    rep(i,1,n+1) cin>>arr[i];
    rep(i,1,64){
        pp[i] = pow(k,i);
        if(pp[i]>100000000000005||pp[i]<-100000000000005) break;
        len++;
    }
    //rep(i,1,len+1) printf("%lld\n",pp[i],i==len?'\n':' ');
    rep(i,1,n+1) sum[i] = sum[i-1]+arr[i];

    map<ll,int> mymap;
    ll ans = 0;
    rep(i,1,n+1) if(arr[i]==1) ans++;
    /*rep(i,1,n+1) rep(j,1,len+1) if(arr[i]==pp[j]){
        flag[i] = 1;
        printf("ii ");de(i);
        ans++;
    }*/
    mymap[0] = 1;
    rep(i,1,n+1){
        rep(j,1,len+1){
            ll tmp = sum[i]-pp[j];
            if(mymap.count(tmp)){
                //dd(i);dd(j);dd(tmp);de(mymap[tmp]);
                ans+=mymap[tmp];
            }
            //ans+=mymap[tmp];
        }
        //if(flag[i]) ans--;
        mymap[sum[i]]++;
    }
    cout<<ans<<endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << ", "
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

ll arr[maxn] , sum[maxn];
int flag[maxn];
int main()
{
    ll n,k;
    ll pp[64];
    int len = 0;
    cin>>n>>k;

    rep(i,1,n+1) cin>>arr[i];

    if(k==1){
        pp[0] = 1;
        len = 0;
    }
    else if(k==-1){
        pp[0] = 1;
        pp[1] = -1;
        len = 1;
    }
    else if(k!=1 && k!=-1){
        len = 0;
        pp[0] = 1;
        rep(i,1,64){
            pp[i] = pow(k,i);
            if(pp[i]>100000000000005||pp[i]<-100000000000005) break;
            len++;
        }
    }

    rep(i,1,n+1) sum[i] = sum[i-1]+arr[i];

    map<ll,ll> mymap;
    ll ans = 0;
    //rep(i,1,n+1) if(arr[i]==1) ans++;

    mymap[0] = 1;
    rep(i,1,n+1){
        //dd(i);de(sum[i]);
        rep(j,0,len+1){
            ll tmp = sum[i]-pp[j];
            //if(arr[i]==0&&tmp==0) continue;
            if(mymap.count(tmp)){
                //dd(i);dd(j);dd(tmp);de(mymap[tmp]);
                ans+=mymap[tmp];
            }
        }
        mymap[sum[i]]++;
        //mymap[0] = 1;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;
//multiset<long long> s;
map<long long, long long > mm;

long long howmany(long long KK) {
    long long pneed;
    mm.clear();
    mm[0]=1;
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += mm[pneed];
        mm[b[i]]++;
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%I64d %I64d",&n, &k);
    //cin >> n >> k;
    for(int i = 1; i <= n; i++)  scanf("%I64d",&a[i]);
        //cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 1e15+7) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;
multiset<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 100000000000000007L) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;

set<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 10000000000000007L) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;

long long howmany(long long KK) {
    long long pneed;
set<long long> s;
//    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
//    freopen("input.txt","r",stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 100000000000000007L) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <iostream>
#include <unordered_map>

using namespace std;

#define MAXVAL 100000000000000

long long n,k;
long long P[100005];
unordered_map<long long,long long> m;

long long howmany(long long kk){
    long long r=0;

    for(int i=0;i<=n;i++){
        r+=m[P[i]-kk];
        m[P[i]]+=1;
    }

    return r;
}

int main()
{
    m.reserve(100005);
    m.max_load_factor(0.25);

    cin>>n>>k;

    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        P[i]=P[i-1]+a;
    }

    long long kk=1;
    long long res=0;

    while(kk<=MAXVAL && k!=1 && k!=-1){
        res+=howmany(kk);
        kk*=k;
        m.clear();
    }

    if(k==1){
        res+=howmany(k);
    }else if(k==-1){
        res+=howmany(1);
        m.clear();
        res+=howmany(-1);
    }

    cout<<res;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;
multiset<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%I64d %I64d",&n, &k);
    //cin >> n >> k;
    for(int i = 1; i <= n; i++)  scanf("%I64d",&a[i]);
        //cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 100000000000000007L) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;

set<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
//    freopen("input.txt","r",stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 100000000000000007L) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;
multiset<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%I64d %I64d",&n, &k);
    //cin >> n >> k;
    for(int i = 1; i <= n; i++)  scanf("%I64d",&a[i]);
        //cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 1e15+7) break;
    }
    cout<<gres<<endl;

    return 0;
}


#include <iostream>
#include <unordered_map>

using namespace std;

#define MAXVAL 100000000000000

long long n,k;
long long P[100005];
unordered_map<long long,long long> m;

long long howmany(long long kk){
    long long r=0;

    for(int i=0;i<=n;i++){
        r+=m[P[i]-kk];
        m[P[i]]+=1;
    }

    return r;
}

int main()
{
    m.reserve( 131072);
    m.max_load_factor(0.25);

    cin>>n>>k;

    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        P[i]=P[i-1]+a;
    }

    long long kk=1;
    long long res=0;

    while(kk<=MAXVAL && k!=1 && k!=-1){
        res+=howmany(kk);
        kk*=k;
        m.clear();
    }

    if(k==1){
        res+=howmany(k);
    }else if(k==-1){
        res+=howmany(1);
        m.clear();
        res+=howmany(-1);
    }

    cout<<res;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long a[DIM];
long long n,k,i,j;
vector<long long> b;

set<long long> s;

long long howmany(long long KK) {
    long long pneed;
    s.clear();
    s.insert(b[0]);
    long long res = 0;
    for(int i = 1; i <= n; i++) {
        pneed = b[i] - KK;
        res += s.count(pneed);
        s.insert(b[i]);
    }
    return res;
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++) b.push_back(0);

    b[0] = 0;
    for(int i = 1; i <= n; i++) b[i] = b[i-1]+a[i];

    long long gres = 0;
    for(long long x = 1; ;) {
        gres += howmany(x);
        if(k==1) break;
        if(k==-1 && x == -1) break;
        x*=k;
        if(abs(x) > 1000000000000000) break;
    }

    cout<<gres<<endl;

    return 0;
}


#include <iostream>
#include <unordered_map>

using namespace std;

#define MAXVAL 100000000000000

long long n,k;
long long P[100005];
unordered_map<long long,long long> m;

long long howmany(long long kk){
    long long r=0;

    for(int i=0;i<=n;i++){
        r+=m[P[i]-kk];
        m[P[i]]+=1;
    }

    return r;
}

int main()
{
    m.reserve(10000005);
    m.max_load_factor(0.25);

    cin>>n>>k;

    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        P[i]=P[i-1]+a;
    }

    long long kk=1;
    long long res=0;

    while(kk<=MAXVAL && k!=1 && k!=-1){
        res+=howmany(kk);
        kk*=k;
        m.clear();
    }

    if(k==1){
        res+=howmany(k);
    }else if(k==-1){
        res+=howmany(1);
        m.clear();
        res+=howmany(-1);
    }

    cout<<res;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
multiset<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=1;
	else if(k==-1)
	{
		mxp=2;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	for(int i=1;i<=n;++i)
	{
		sum[i]=sum[i-1]+a[i];
		st.insert(sum[i]);
	}
	long long ans =0;
	st.insert(0);
	for(int i=0;i<=mxp;++i)
	{
		for(int j=1;j<=n;++j)
		{
			//cout<<sum[j]-pk[i]<<endl;
			if(sum[j]>=0)
			if(st.count(sum[j]-pk[i]))ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
multiset<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=1;
	else if(k==-1)
	{
		mxp=2;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	for(int i=1;i<=n;++i)
	{
		sum[i]=sum[i-1]+a[i];
		st.insert(sum[i]);
	}
	long long ans =0;
	for(int i=0;i<=mxp;++i)
	{
		for(int j=0;j<=n;++j)
		{
			//cout<<sum[j]-pk[i]<<endl;
			if(sum[i]>=0)
			ans+=st.count(pk[i]-sum[j]);
			//cout<<pk[i]-sum[j]<<" ";
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
multiset<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		st.insert(sum[j]);
	}

	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			if(sum[j]>=0)
			ans+=st.count(pk[i]-sum[j]);
			//cout<<pk[i]-sum[j]<<" ";
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		st.insert(sum[j]);
	}
	long long ans =0;
	st.insert(0);
	for(long long j=1;j<=n;++j)
	{
		for(ll i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	pk[0]=1;
	if(k==1)mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}else{
		ktemp=k;
		while(abs(ktemp)<=10000000000000000LL)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	pk[0]=1;
	if(k==1)mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}else{
		ktemp=k;
		while(abs(ktemp)<=10000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	pk[0]=1;
	if(k==1)mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}else{
		ktemp=k;
		while(abs(ktemp)<=100000000000000000LL)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<map>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long sum[100010];
long long pk[100];
map<ll,int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	long long ans =0;
	st.clear();
	st[0]=1;
	for(int j=1;j<=n;++j)
	{
		long long t;
		cin>>t;
		sum[j]=sum[j-1]+t;
		for(ll tt=1;abs(tt)<=100000000000010LL;)
		{
			ans+=st[sum[j]-tt];
			tt*=k;
			if(tt==1)break;
		}
		st[sum[j]]++;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
multiset<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=1;
	else if(k==-1)
	{
		mxp=2;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.count(sum[j]-pk[i]))ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(long long j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		st.insert(sum[j]);
		for(ll i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
set<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(ll i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(abs(ktemp)<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.find(sum[j]-pk[i])!=st.end())ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#define ll long long
using namespace std;
long long n,k;
long long ktemp;
long long mxp=0;
long long a[100010];
long long sum[100010];
long long pk[100];
//long long mx=-9999999999999999LL;
//long long mix = 99999999999999999LL;
multiset<long long>st;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		//mx=max(mx,a[i]);
		//mix=min(mix,a[i]);
	}
	pk[0]=1;
	if(k==1)
		mxp=0;
	else if(k==-1)
	{
		mxp=1;
		pk[1]=-1;
	}
	else
	{
		ktemp=k;
		while(ktemp<=1000000000LL*n)
		{
			mxp++;
			pk[mxp]=ktemp;
			ktemp*=k;
		}
	}
	long long ans =0;
	st.insert(0);
	for(int j=1;j<=n;++j)
	{
		sum[j]=sum[j-1]+a[j];
		for(int i=0;i<=mxp;++i)
		{
			//cout<<sum[j]-pk[i]<<endl;
			//if(sum[j]>=0)
			if(st.count(sum[j]-pk[i]))ans++;
			//cout<<pk[i]-sum[j]<<" ";
		}
		st.insert(sum[j]);
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e10*alln;
    int cnt = 0;
    for(long long targ = 1; targ <= lim ;cnt++,targ*=k){
        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        Umap.clear();
        for(int i=0;i<=alln;++i){

            long long want = num[i]-targ;
            if( Umap.find(want) != Umap.end() )
                ans += Umap[want];
            Umap[num[i] ]++;
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ-num[i];
            ans += Umap[want];
            Umap[num[i] ]--;
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }

        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ+num[i];
            Umap[num[i] ]--;
            ans += Umap[want];
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e10*alln;
    for(long long targ = 1; targ <= lim ;targ*=k){
        Umap.clear();
        for(int i=0;i<=alln;++i){

            long long want = num[i]-targ;
            if( Umap.find(want) != Umap.end() )
                ans += Umap[want];
            Umap[num[i] ]++;
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        Umap.clear();

        long long sum = 0;
        for(int i=1;i<=alln;i++)
        {
            Umap[sum]++;
            sum += num[i];
            ans += Umap[sum-targ];
            //printf("\t\tsum = %I64d   (%d)\n",sum,cnt[sum-now]);
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e9*alln;
    int cnt = 0;
    for(long long targ = 1; targ <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        Umap.clear();
        for(int i=0;i<=alln;++i){

            long long want = num[i]-targ;
            if( Umap.find(want) != Umap.end() )
                ans += Umap[want];
            Umap[num[i] ]++;
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    long long targ = 1;
    for(int j=0; j<=50 && ab(targ) < 1e15 ;j++,cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }

        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ+num[i];
            Umap[num[i] ]--;
            ans += Umap[want];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap(100000);
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    long long targ = 1;
    for(int j=0; j<=50 && ab(targ) < 1e15 ;j++,cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }

        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ+num[i];
            Umap[num[i] ]--;
            ans += Umap[want];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        Umap.clear();

        long long sum = 0;
        for(int i=1;i<=alln;i++)
        {
            Umap[sum]++;
            sum += num[i];
            ans += Umap[sum-targ];
            //printf("\t\tsum = %I64d   (%d)\n",sum,cnt[sum-now]);
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    long long targ = 1;
    for(int j=0; j<=50 ;j++,cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }

        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ+num[i];
            Umap[num[i] ]--;
            ans += Umap[want];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }

        for(int i=0;i<=alln;++i){
            Umap[ num[i] ]++;
        }

        for(int i=0;i<=alln;++i){
            long long want = targ+num[i];
            Umap[num[i] ]--;
            ans += Umap[want];

        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<unordered_map>
using namespace std;
int alln;
long long k;
unordered_map <long long,long long> Umap;
long long num[100005];

long long ab(long long a){
    if(a >= 0)
        return a;
    return -a;
}

int main()
{
    scanf("%d%lld",&alln,&k);
    for(int i=1;i<=alln;++i){
        scanf("%lld",&num[i]);
        num[i] += num[i-1];
    }
    long long ans = 0;
    long long lim = 1e15;

    int cnt = 0;
    for(long long targ = 1; ab(targ) <= lim ;cnt++,targ*=k){

        if(k == -1){
            if(cnt == 2)
                break;
        }
        else if(k == 1){
            if(cnt == 1)
                break;
        }
        Umap.clear();
        for(int i=0;i<=alln;++i){

            long long want = num[i]-targ;
            if( Umap.find(want) != Umap.end() )
                ans += Umap[want];
            Umap[num[i] ]++;
        }

    }
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (f == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1 || (k == -1 && f == -1)) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1; f <= 10; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1 || k == -1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1; f <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if ((k == 1 || k == -1) && f == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (k == 1) {
			ans += cnt[sum[i] + 1];
		} else if (k == -1) {
			ans += cnt[sum[i] + 1] + cnt[sum[i] - 1];
		} else {
			for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
				ans += cnt[sum[i] + f];
			}
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
unordered_map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (k == 1) {
			ans += cnt[sum[i] + 1];
		} else if (k == -1) {
			ans += cnt[sum[i] + 1] + cnt[sum[i] - 1];
		} else {
			for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
				ans += cnt[sum[i] + f];
			}
		}
		cnt[sum[i]]++;
	}
	printf("%lld\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (k == 1) {
			ans += cnt[sum[i] + 1];
		} else if (k == -1) {
			ans += cnt[sum[i] + 1] + cnt[sum[i] - 1];
		} else {
			for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
				ans += cnt[sum[i] + f];
			}
		}
		cnt[sum[i]]++;
	}
	printf("%lld\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;

int n, k;
long long sum[MAXN];
map<long long, int> cnt;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &sum[i]);
		sum[i] += sum[i - 1];
	}
	cnt[sum[n]] = 1;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (long long f = 1ll; abs(f) <= 100000000000000ll; f *= k) {
			ans += cnt[sum[i] + f];
			if (k == 1) break;
		}
		cnt[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const int MAXN = 1e5 + 5;
const int MAXM = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LLINF = 2e18;
const ll MAXNUM = 1e17;

ll mul, n, k, ans, x;
ll pref[MAXN];
ll pw[100];
unordered_map<ll, ll> m;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    m.reserve(1 << 15);
    m.max_load_factor(0.25);
    cin >> n >> k;

    pref[0] = 0;

    for (int i = 1; i <= n; i++) {
        cin >> x;
        pref[i] = pref[i - 1] + x;
    }

    // cout << "PREF:" << endl;
    // forn(i, n + 1) {
    //     cout << pref[i] << ' ';
    // }
    // cout << endl;

    int cnt = 0, MAXX;
    if (k == 1) {
        MAXX = 0;
        pw[0] = 1;
    } else if (k == -1) {
        MAXX = 1;
        pw[0] = 1;
        pw[1] = -1;
    } else {
        mul = 1;
        while (abs(mul) < MAXNUM) {
            pw[cnt] = mul;
            mul *= k;
            cnt++;
        }
        MAXX = cnt - 1;
    }
    // forn(i, MAXX + 1) {
    //     cout << pw[i] << ' ' << endl;
    // }
    // cout << "MAXX = " << MAXX << endl;

    m[0] = 1;
    for (int rr = 1; rr <= n; rr++) {
        for (int x = 0; x <= MAXX; x++) {
            ans += m[pref[rr] - pw[x]];
            // if (m[pref[rr] - pw[x]]) {
            //     cout << "rr " << rr << " ans " << ans << " pref[rr] - pw[x] " << pref[rr] - pw[x];
            //     cout << ' ' << pref[rr] << ' ' << pw[x] << endl;
            // }
        }
        m[pref[rr]]++;
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const int MAXN = 1e5 + 5;
const int MAXM = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LLINF = 2e18;
const ll MAXNUM = 1e17;

ll mul, n, k, ans, x;
ll pref[MAXN];
ll pw[100];
unordered_map<ll, ll> m;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    m.reserve(4096);
    m.max_load_factor(0.25);
    cin >> n >> k;

    pref[0] = 0;

    for (int i = 1; i <= n; i++) {
        cin >> x;
        pref[i] = pref[i - 1] + x;
    }

    // cout << "PREF:" << endl;
    // forn(i, n + 1) {
    //     cout << pref[i] << ' ';
    // }
    // cout << endl;

    int cnt = 0, MAXX;
    if (k == 1) {
        MAXX = 0;
        pw[0] = 1;
    } else if (k == -1) {
        MAXX = 1;
        pw[0] = 1;
        pw[1] = -1;
    } else {
        mul = 1;
        while (abs(mul) < MAXNUM) {
            pw[cnt] = mul;
            mul *= k;
            cnt++;
        }
        MAXX = cnt - 1;
    }
    // forn(i, MAXX + 1) {
    //     cout << pw[i] << ' ' << endl;
    // }
    // cout << "MAXX = " << MAXX << endl;

    m[0] = 1;
    for (int rr = 1; rr <= n; rr++) {
        for (int x = 0; x <= MAXX; x++) {
            ans += m[pref[rr] - pw[x]];
            // if (m[pref[rr] - pw[x]]) {
            //     cout << "rr " << rr << " ans " << ans << " pref[rr] - pw[x] " << pref[rr] - pw[x];
            //     cout << ' ' << pref[rr] << ' ' << pw[x] << endl;
            // }
        }
        m[pref[rr]]++;
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define forn(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const int MAXN = 1e5 + 5;
const int MAXM = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LLINF = 2e18;
const ll MAXNUM = 1e14;

ll mul, n, k, ans, x, sum;
ll pref[MAXN];
ll pw[150];
unordered_map<ll, int> m;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;

    pref[0] = 0;

    for (int i = 1; i <= n; i++) {
        cin >> x;
        pref[i] = pref[i - 1] + x;
    }

    int cnt = 0, MAXX;
    if (k == 1) {
        MAXX = 0;
        pw[0] = 1;
    } else if (k == -1) {
        MAXX = 1;
        pw[0] = 1;
        pw[1] = -1;
    } else {
        mul = 1;
        while (abs(mul) <= MAXNUM) {
            pw[cnt] = mul;
            mul *= k;
            cnt++;
        }
        MAXX = cnt - 1;
    }

    m[0] = 1;
    for (int rr = 1; rr <= n; rr++) {
        for (int x = 0; x <= MAXX; x++) {
            ans += m[pref[rr] - pw[x]];
        }
        m[pref[rr]]++;
    }

    cout << ans << endl;

    return 0;
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class main{
	 public static void main(String args[])
	    {
		 	Scanner sc = new Scanner(System.in);
		 	int t = sc.nextInt();
		 	while(t-->0)
		 	{
		 		String s = sc.next();
		 		System.out.println(s.length());
		 	}

	    }
}


import java.util.*;
public class A {
    static Scanner scan = new Scanner(System.in);
    public static void main(String[] args) {
        int t = scan.nextInt();
        while(t != 0) {
            String str = scan.next();
            System.out.println(str.length());
            t--;
        }
    }
}


import java.util.Scanner;

public class StrangeFunction {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int tc=s.nextInt();
		while(tc-->0) {
			long num=s.nextLong();
			System.out.println(coundigits(num));

		}
		s.close();
	}

	private static int coundigits(long num) {
		int count=0;
		while(num>0) {
			count++;
			num=num/10;
		}
		return count;
	}

}


import java.util.HashMap;
import java.util.Scanner;

public class StrangeFunction {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int tc=s.nextInt();
		while(tc-->0) {
			HashMap<Long,Integer> hm=new HashMap<>();
			hm.put((long) 1,1);
			long num=s.nextLong();
			for(long i=1;i<=num;i++) {
				if(i%10==0) {
					long fx=strangeFunction(i);
					if(!hm.containsKey(i/fx)) {
						hm.put(i/fx,1);
					}

				}

			}
			System.out.println(hm.size());

		}
		s.close();
	}

	private static long strangeFunction(long num) {
		while(num>0) {
			if(num%10==0) {
				num=num/10;
			}else {
				break;
			}
		}
		return num;

	}

}


import java.math.BigInteger;
import java.util.Scanner;

public class StrangeFunction {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int tc=s.nextInt();
		while(tc-->0) {
			BigInteger n =s.nextBigInteger();
			System.out.println(coundigits(n));

		}
		s.close();
	}

	private static int coundigits(BigInteger number) {
		int digitSize = 0;
	    while (!number.equals(BigInteger.ZERO)) {
	        number = number.divide(BigInteger.TEN);
	        digitSize++;
	    }
	    return digitSize;
	}
}


import java.util.HashMap;
import java.util.Scanner;

public class StrangeFunction {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int tc=s.nextInt();
		while(tc-->0) {
			HashMap<Long,Integer> hm=new HashMap<>();
			long num=s.nextLong();
			for(long i=1;i<=num;i++) {
				long fx=strangeFunction(i);
				if(!hm.containsKey(i/fx)) {
					hm.put(i/fx,1);
				}

			}
			System.out.println(hm.size());

		}
		s.close();
	}

	private static long strangeFunction(long num) {
		while(num>0) {
			if(num%10==0) {
				num=num/10;
			}else {
				break;
			}
		}
		return num;

	}

}


import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int test = scanner.nextInt();
        for (int i = 0; i < test; i++) {

            BigInteger n = scanner.nextBigInteger();
            System.out.println(countDigit(n));

        }

    }
    static long countDigit(BigInteger n)
    {
        if (n.equals(BigInteger.ZERO))
            return 0;
        return countDigit(n.divide(BigInteger.TEN))+1 ;
    }

}


import java.util.*;
public class S
{

      public static void main(String []  args)
      {

        Scanner obj = new Scanner(System.in);
         int t = obj.nextInt();
         while(t-->0)
         {
         	String s = obj.next();
            System.out.println(s.length());

         }

      }
}


//!/bin/env/java

import java.util.*;
import java.math.BigInteger;
public class StrangeFunctions {
    public static void main(String []args){
        Scanner read = new Scanner(System.in);
        int test = read.nextInt();
        while(test-- > 0){
            BigInteger n = read.nextBigInteger();
            int cnt = 0;
            //String object = "0";
            while(true){
                if(n.equals(BigInteger.ZERO))
                    break;
                n = n.divide(BigInteger.valueOf(10));
                cnt++;
            }
            System.out.println(cnt);
        }
        //System.out.println(test);
        read.close();
    }
}


import java.math.BigInteger;
import java.util.Scanner;

public class Test1 {

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int i=0;i<t;i++) {
			BigInteger a = sc.nextBigInteger();
			BigInteger c = BigInteger.valueOf(1);
			int count = 0;
			while(c.compareTo(a)!=1) {
				count++;
				c = c.multiply(BigInteger.valueOf(10));
			}
			System.out.println(count);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Random;
import java.io.FileWriter;
import java.io.PrintWriter;
/*
    Solution Created: 16:41:10 30/11/2020
    Custom Competitive programming helper.
*/
public class Main {
	public static void solve(Reader in, Writer out) {
		int t = in.nextInt();
		while(t-->0){
			String s = in.next();
			int n = s.length();
			out.println(n);
		}
	}

	public static void main(String[] args) {
		Reader in = new Reader();
		Writer out = new Writer();
		solve(in, out);
		out.exit();
	}

static class Reader {
	static BufferedReader br;
	static StringTokenizer st;
	private int charIdx = 0;
	private String s;

	public Reader() {
		this.br = new BufferedReader(new InputStreamReader(System.in));
	}

	public Reader(String f){
		try {
			this.br = new BufferedReader(new FileReader(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public double[] nd(int n) {
		double[] a = new double[n];
		for (int i = 0; i < n; i++)
			a[i] = nextDouble();
		return a;
	}

	public char nextChar() {
		if (s == null || charIdx >= s.length()) {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			s = st.nextToken();
			charIdx = 0;
		}
		return s.charAt(charIdx++);
	}

	public long[] nl(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}

	public char[] nca() {
		return next().toCharArray();
	}

	public String[] nS(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++)
			a[i] = next();
		return a;
	}

	public int nextInt() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Integer.parseInt(st.nextToken());
	}

	public double nextDouble() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Double.parseDouble(st.nextToken());
	}

	public Long nextLong() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Long.parseLong(st.nextToken());
	}

	public String next() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return st.nextToken();
	}

	public static void readLine() {
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
		}
	}
}

static class Util{
		private static Random random = new Random();
		static long[] fact;
		public static void initFactorial(int n, long mod) {
			fact = new long[n+1];
			fact[0] = 1;
			for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod;
		}
		public static long modInverse(long a, long MOD) {
			long[] gcdE = gcdExtended(a, MOD);
			if (gcdE[0] != 1) return -1; // Inverted doesn't exist
			long x = gcdE[1];
			return (x % MOD + MOD) % MOD;
		}
		public static long[] gcdExtended(long p, long q) {
			if (q == 0) return new long[] { p, 1, 0 };
			long[] vals = gcdExtended(q, p % q);
			long tmp = vals[2];
			vals[2] = vals[1] - (p / q) * vals[2];
			vals[1] = tmp;
			return vals;
		}
		public static long nCr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}
		public static long nCr(int n, int r) {
			return (fact[n]/fact[r])/fact[n-r];
		}
		public static long nPr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}
		public static long nPr(int n, int r) {
			return fact[n]/fact[n-r];
		}
		public static boolean isPrime(int n) {
	        if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (int i = 5; i * i <= n; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	            return false;
	        return true;
	    }
		public static boolean isPrime(long n) {
	        if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (long i = 5; i * i <= n; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	            return false;
	        return true;
	    }
	    public static int lowerBound(int[] a, int v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(v<=a[mid]) h = mid;
	    		else l = mid+1;
	    	}
	    	return l;
	    }
	    public static int lowerBound(long[] a, long v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(v<=a[mid]) h = mid;
	    		else l = mid+1;
	    	}
	    	return l;
	    }
	    public static int upperBound(int[] a, int v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(a[mid]<=v) l = mid+1;
	    		else h = mid;
	    	}
	    	return l;
	    }
	    public static int upperBound(long[] a, long v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(a[mid]<=v) l = mid+1;
	    		else h = mid;
	    	}
	    	return l;
	    }
	    public static boolean[] getSieve(int n) {
	        boolean[] isPrime = new boolean[n+1];
	        for (int i = 2; i <= n; i++) isPrime[i] = true;
	        for (int i = 2; i*i <= n; i++) if (isPrime[i])
	                for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
	        return isPrime;
	    }
	    public static int gcd(int a, int b) {
	    	int tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }
	    public static long gcd(long a, long b) {
	    	long tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }
	    public static int random(int min, int max) {
	    	return random.nextInt(max-min+1)+min;
	    }
		public static void dbg(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
		public static void reverse(int[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				int tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(int[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(long[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				long tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(long[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(float[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				float tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(float[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(double[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				double tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(double[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(char[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				char tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(char[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static <T> void reverse(T[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				T tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static <T> void reverse(T[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void shuffle(int[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            int t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(long[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            long t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(float[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            float t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(double[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            double t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(char[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            char t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static <T> void shuffle(T[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            T t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
		public static void sortArray(int[] a) {
	        shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(long[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(float[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(double[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(char[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static <T extends Comparable<T>> void sortArray(T[] a) {
	        Arrays.sort(a);
	    }
	}

static class Writer {
	private PrintWriter pw;
	public Writer(){
		pw = new PrintWriter(System.out);
	}

	public Writer(String f){
		try {
			pw = new PrintWriter(new FileWriter(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void printArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}
	public void printlnArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}
	public void printArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}
	public void printlnArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}
	public void print(Object o) {
		pw.print(o.toString());
	}
	public void println(Object o) {
		pw.println(o.toString());
	}
	public void println() {
		pw.println();
	}
	public void flush() {
		pw.flush();
	}
	public void exit() {
		pw.close();
	}
}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Random;
import java.io.FileWriter;
import java.io.PrintWriter;
/*
    Solution Created: 16:40:53 30/11/2020
    Custom Competitive programming helper.
*/
public class Main {
	public static void solve(Reader in, Writer out) {
		int t = in.nextInt();
		while(t-->0){
			String s = in.next();
			int n = s.length();
			int l = 0, r = n-1;
			while(s.charAt(l)=='0') l++;
			while(s.charAt(r)=='0') r--;
			out.println(r-l+1);
		}
	}

	public static void main(String[] args) {
		Reader in = new Reader();
		Writer out = new Writer();
		solve(in, out);
		out.exit();
	}

static class Reader {
	static BufferedReader br;
	static StringTokenizer st;
	private int charIdx = 0;
	private String s;

	public Reader() {
		this.br = new BufferedReader(new InputStreamReader(System.in));
	}

	public Reader(String f){
		try {
			this.br = new BufferedReader(new FileReader(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public double[] nd(int n) {
		double[] a = new double[n];
		for (int i = 0; i < n; i++)
			a[i] = nextDouble();
		return a;
	}

	public char nextChar() {
		if (s == null || charIdx >= s.length()) {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			s = st.nextToken();
			charIdx = 0;
		}
		return s.charAt(charIdx++);
	}

	public long[] nl(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}

	public char[] nca() {
		return next().toCharArray();
	}

	public String[] nS(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++)
			a[i] = next();
		return a;
	}

	public int nextInt() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Integer.parseInt(st.nextToken());
	}

	public double nextDouble() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Double.parseDouble(st.nextToken());
	}

	public Long nextLong() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return Long.parseLong(st.nextToken());
	}

	public String next() {
		if (st == null || !st.hasMoreTokens())
			try {
				readLine();
			} catch (Exception e) {
			}
		return st.nextToken();
	}

	public static void readLine() {
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
		}
	}
}

static class Util{
		private static Random random = new Random();
		static long[] fact;
		public static void initFactorial(int n, long mod) {
			fact = new long[n+1];
			fact[0] = 1;
			for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod;
		}
		public static long modInverse(long a, long MOD) {
			long[] gcdE = gcdExtended(a, MOD);
			if (gcdE[0] != 1) return -1; // Inverted doesn't exist
			long x = gcdE[1];
			return (x % MOD + MOD) % MOD;
		}
		public static long[] gcdExtended(long p, long q) {
			if (q == 0) return new long[] { p, 1, 0 };
			long[] vals = gcdExtended(q, p % q);
			long tmp = vals[2];
			vals[2] = vals[1] - (p / q) * vals[2];
			vals[1] = tmp;
			return vals;
		}
		public static long nCr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}
		public static long nCr(int n, int r) {
			return (fact[n]/fact[r])/fact[n-r];
		}
		public static long nPr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}
		public static long nPr(int n, int r) {
			return fact[n]/fact[n-r];
		}
		public static boolean isPrime(int n) {
	        if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (int i = 5; i * i <= n; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	            return false;
	        return true;
	    }
		public static boolean isPrime(long n) {
	        if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (long i = 5; i * i <= n; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	            return false;
	        return true;
	    }
	    public static int lowerBound(int[] a, int v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(v<=a[mid]) h = mid;
	    		else l = mid+1;
	    	}
	    	return l;
	    }
	    public static int lowerBound(long[] a, long v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(v<=a[mid]) h = mid;
	    		else l = mid+1;
	    	}
	    	return l;
	    }
	    public static int upperBound(int[] a, int v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(a[mid]<=v) l = mid+1;
	    		else h = mid;
	    	}
	    	return l;
	    }
	    public static int upperBound(long[] a, long v) {
	    	int l = 0, h = a.length;
	    	while(l<h) {
	    		int mid = (l+h)/2;
	    		if(a[mid]<=v) l = mid+1;
	    		else h = mid;
	    	}
	    	return l;
	    }
	    public static boolean[] getSieve(int n) {
	        boolean[] isPrime = new boolean[n+1];
	        for (int i = 2; i <= n; i++) isPrime[i] = true;
	        for (int i = 2; i*i <= n; i++) if (isPrime[i])
	                for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
	        return isPrime;
	    }
	    public static int gcd(int a, int b) {
	    	int tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }
	    public static long gcd(long a, long b) {
	    	long tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }
	    public static int random(int min, int max) {
	    	return random.nextInt(max-min+1)+min;
	    }
		public static void dbg(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
		public static void reverse(int[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				int tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(int[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(long[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				long tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(long[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(float[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				float tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(float[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(double[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				double tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(double[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void reverse(char[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				char tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static void reverse(char[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static <T> void reverse(T[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				T tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }
		public static <T> void reverse(T[] s) {
			reverse(s, 0, s.length-1);
	    }
		public static void shuffle(int[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            int t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(long[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            long t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(float[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            float t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(double[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            double t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static void shuffle(char[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            char t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
	    public static <T> void shuffle(T[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            T t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }
		public static void sortArray(int[] a) {
	        shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(long[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(float[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(double[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static void sortArray(char[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }
		public static <T extends Comparable<T>> void sortArray(T[] a) {
	        Arrays.sort(a);
	    }
	}

static class Writer {
	private PrintWriter pw;
	public Writer(){
		pw = new PrintWriter(System.out);
	}

	public Writer(String f){
		try {
			pw = new PrintWriter(new FileWriter(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void printArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}
	public void printlnArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}
	public void printArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}
	public void printlnArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}
	public void print(Object o) {
		pw.print(o.toString());
	}
	public void println(Object o) {
		pw.println(o.toString());
	}
	public void println() {
		pw.println();
	}
	public void flush() {
		pw.flush();
	}
	public void exit() {
		pw.close();
	}
}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * @Author hello_kiss
 * @Date 2020/11/30 22:33
 */
public class Main {
    public static void main(String[] args) {
        int t;
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        t=scan.nextInt();
        while(t-->0){
            String s=scan.next();
            System.out.println(s.length());
        }
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * @Author hello_kiss
 * @Date 2020/11/30 22:33
 */
public class A {
    public static void main(String[] args) {
        int t;
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        t=scan.nextInt();
        while(t-->0){
            String s=scan.next();
            System.out.println(s.length());
        }
    }
}


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

public class strangefunctions {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        int testcases=Integer.parseInt(br.readLine());
        for(int i=0;i<testcases;i++){
            System.out.println(br.readLine().length());
        }
    }
}


import java.util.*;
public class Ex{
	public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int t=sc.nextInt();
       while(t-->0){
       	   String s=sc.next();
       	   int n=s.length();
       	   System.out.println(n);
       }
	}
}


import java.util.*;

public class l {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(s.length());
        sc.close();
    }
}


import java.util.*;

public class l {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n + 1; i++) {
            String s = sc.nextLine();

            a[i - 1] = s.length();
        }
        for (int i = 1; i < n + 1; i++)
            System.out.println(a[i]);
        sc.close();
    }
}


import java.math.BigInteger;
import java.text.*;
import java.util.*;
import java.io.*;

/**
 * @author : soumitri12
 */

public class Solution {
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (final IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (final IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Pair {
        int ff, ss;

        public Pair(int ff, int ss) {
            this.ff = ff;
            this.ss = ss;
        }
    }

    public static void main(final String[] args) {
        final FastReader sc = new FastReader();
        final PrintWriter out = new PrintWriter(System.out);
        StringBuffer sb = new StringBuffer();
        // your code starts here
        int t = sc.nextInt();
        while (t-- > 0) {
            String s = sc.next();
            out.println(s.length());
        }

        out.close();
    }
}


import java.util.*;
import java.math.*;
import java.io.*;
 public class B{
static int[] dx={-1,1,0,0};
static int[] dy={0,0,1,-1};
    static FastReader scan=new FastReader();
   public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  static ArrayList<Pair>es;
  static LinkedList<Pair>edges[][];
   static boolean prime[];
   static void sieve(int n)
    {

        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {

            if(prime[p] == true)
            {

                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

 public static boolean areSame(int []arr)
    {
        // Put all array elements in a HashSet
        Set<Integer>s=new HashSet<Integer>();
        for(int i=0;i<arr.length;i++)
            s.add(arr[i]);

        // If all elements are same, size of
        // HashSet should be 1. As HashSet contains only distinct values.
        return (s.size() == 1);
    }

     public static int lowerBound(long[] array, int length, long value) {
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            //checks if the value is less than middle element of the array
            if (value <= array[mid]) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
    }
    public static int upperBound(long[] array, int length, long value) {
        int low = 0;
        int high = length;
        while (low < high) {
            final int mid = low+(high-low) / 2;
            if ( array[mid]>value) {
                high = mid ;
            } else {
                low = mid+1;
            }
        }
        return low;
    }
static long mod(long x,long y)
    {
        if(x<0)
            x=x+(-x/y+1)*y;
        return x%y;
    }

    static boolean isPowerOfTwo(int n)
{
    if(n==0)
    return false;

return (int)(Math.ceil((Math.log(n) / Math.log(2)))) ==
       (int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static int CeilIndex(int A[], int l, int r, int key)
    {
        while (r - l > 1) {
            int m = l + (r - l) / 2;
            if (A[m] >= key)
                r = m;
            else
                l = m;
        }

        return r;
    }

    static int LongestIncreasingSubsequenceLength(int A[], int size)
    {
        // Add boundary case, when array size is one

        int[] tailTable = new int[size];
        int len; // always points empty slot

        tailTable[0] = A[0];
        len = 1;
        for (int i = 1; i < size; i++) {
            if (A[i] < tailTable[0])
                // new smallest value
                tailTable[0] = A[i];

            else if (A[i] >= tailTable[len - 1])
                // A[i] wants to extend largest subsequence
                tailTable[len++] = A[i];

            else
                // A[i] wants to be current end candidate of an existing
                // subsequence. It will replace ceil value in tailTable
                tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
        }

        return len;
    }
static boolean isprime(long x)
           {
            for(long i=2;i*i<=x;i++)
                if(x%i==0)
                    return false;
                return true;
           }
           static long arr[];

        static int k;

 static boolean can(long x)
 {
    int bl=0;
    int i=0;
    for(int kas=0;i<n&&kas<k;kas++)
    {
        long hasta=arr[i];
        hasta+=x*2;
        while(i<n-1&&arr[i+1]<=hasta)i++;
        i++;

    }
return (i>=n);
 }
static int n,m;
static boolean vis[][];
static boolean light[][];
static boolean e(int x,int y)
{
    return (x>=0&&x<n&&y>=0&&y<n);
}
static int ans=0;
static void dfs(int x,int y)
{
    if(vis[x][y])
        return;
    vis[x][y]=true;
   //light[x][y]=true;
    for(Pair p:edges[x][y])
    {
        if(!light[p.x][p.y]){
            light[p.y][p.y]=true;
            ans++;
            dfs(p.x,p.y);
                    }
    }
    for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(e(nx,ny))
        dfs(nx,ny);
}

}
static int dist(int x1,int y1,int x2,int y2){
return Math.abs(x1-x2)+Math.abs(y1-y2);
}

    public static void main(String[] args)  throws IOException

{
//java.util.Scanner scan=new java.util.Scanner(new File("mootube.in"));
 //PrintWriter out = new PrintWriter (new FileWriter("mootube.out"));
//java.util.Scanner scan=new java.util.Scanner(new File("lightson.in"));
//PrintWriter out = new PrintWriter (new FileWriter("lightson.out"));
    int t=scan.nextInt();
    while(t-->0){
    String s=scan.next();
    out.println(s.length());
 }

out.close();
}
static class special{
    String s;
    String reversed;
    long l;
    special(String s,long l)
    {
        this.s=s;
        this.l=l;
        StringBuilder sb=new StringBuilder(s);
        reversed=sb.reverse().toString();
    }
}
 public static  long pow(long b, long e) {
            long r = 1;
            while (e > 0) {
                if (e % 2 == 1) r = r * b ;
                b = b * b;
                e >>= 1;
            }
            return r;
        }

private static void sort(long[] arr) {
        List<Long> list = new ArrayList<>();
        for (long object : arr) list.add(object);
        Collections.sort(list);
        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
    }
 public static class FastReader {
        BufferedReader br;
        StringTokenizer root;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (root == null || !root.hasMoreTokens()) {
                try {
                    root = new StringTokenizer(br.readLine());
                } catch (Exception addd) {
                    addd.printStackTrace();
                }
            }
            return root.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception addd) {
                addd.printStackTrace();
            }
            return str;
        }
         public int[] nextIntArray(int arraySize) {
            int array[] = new int[arraySize];

            for (int i = 0; i < arraySize; i++) {
                array[i] = nextInt();
            }

            return array;
        }
}
public static class Pair implements Comparable<Pair>{
         int x;
        int  y;
        public Pair(){}
        public Pair(int x1, int y1) {
            x=x1;
            y=y1;
        }
        @Override
        public int hashCode() {
            return (int)(x + 31 * y);
        }
        public String toString() {
            return x + " " + y;
        }
        @Override
        public boolean equals(Object o){
            if (o == this) return true;
            if (o.getClass() != getClass()) return false;
            Pair t = (Pair)o;
            return t.x == x && t.y == y;
        }
        public  int compareTo(Pair o)
        {
             if(x==o.x)
                return y-o.y;
            return x-o.x;
        }
}

}


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

public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      // Start writing your solution here. -------------------------------------
        int testCases = sc.nextInt();
        for (int i = 0 ; i < testCases; i++){
            String testcase = sc.next();
            out.println(testcase.length());
        }

      /*
      int n      = sc.nextInt();        // read input as integer
      long k     = sc.nextLong();       // read input as long
      double d   = sc.nextDouble();     // read input as double
      String str = sc.next();           // read input as String
      String s   = sc.nextLine();       // read whole line as String

      int result = 3*n;
      out.println(result);                    // print via PrintWriter
      */

      // Stop writing your solution here. -------------------------------------
      out.close();
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
}


/* package codechef; // 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. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in=new Scanner(System.in);
		int t;
		t=in.nextInt();
		in.nextLine();
		while(t>0)
		{
		    String s=in.nextLine();
		    System.out.println(s.length());
		    t--;
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution
{
    public static void main(String[] args) throws IOException
    {
        Solution solver = new Solution();
        InputReader in = new InputReader(System.in);
        StringBuilder answer = new StringBuilder();

        int T = in.readInt();
        for (int t = 1; t <= T; t++)
        {
            String n = in.readString();
            answer.append(solver.solve(n)).append('\n');
        }
        System.out.print(answer);
    }

    public int solve(String n)
    {
        return n.length();
    }
}

class InputReader
{
    private InputStream stream;
    private byte[] buffer = new byte[1024];
    private int currentChar;
    private int numberOfChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numberOfChars == -1)
            throw new InputMismatchException();
        if (currentChar >= numberOfChars) {
            currentChar = 0;
            try {
                numberOfChars = stream.read(buffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numberOfChars <= 0)
                return -1;
        }
        return buffer[currentChar++];
    }

    public boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int readInt() {
        int c = read();
        while (isSpace(c))
            c = read();

        byte sign = 1;
        if (c == '-') {
            sign = -1;
            c = read();
        }

        int result = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            result *= 10;
            result += (c - '0');
            c = read();
        }
        while (!isSpace(c));
        return sign * result;
    }

    public long readLong() {
        int c = read();
        while (isSpace(c))
            c = read();

        byte sign = 1;
        if (c == '-') {
            sign = -1;
            c = read();
        }

        long result = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            result *= 10;
            result += (c - '0');
            c = read();
        }
        while (!isSpace(c));

        return sign * result;
    }

    public double readDouble() {
        int c = read();
        while (isSpace(c))
            c = read();

        byte sign = 1;

        if (c == '-') {
            sign = -1;
            c = read();
        }

        double result = 0.0;

        while (!isSpace(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return result * Math.pow(10, readInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            result *= 10;
            result += (c - '0');
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpace(c)) {
                if (c == 'e' || c == 'E')
                    return result * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                result += (c - '0') * m;
                c = read();
            }
        }
        return result * sign;
    }

    public String readString() {
        int c = read();
        while (isSpace(c))
            c = read();
        StringBuilder result = new StringBuilder();
        do {
            result.appendCodePoint(c);
            c = read();
        }
        while (!isSpace(c));

        return result.toString();
    }
}


import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Solution {
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++){
            String s=in.next();
            System.out.println(fun(s));
        }
    }
    public static int fun(String s){
        return s.length();
    }
}


import java.util.*;
public class Soln
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();

        for(int i=0;i<n;i++)
        {int count=0;
            int m=s.nextInt();
            while(m!=0)
            {
                m=m/10;
                count+=1;
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
public class Soln
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextint();

        for(int i=0;i<n;i++)
        {int count=0;
            int m=s.nextInt();
            while(m!=0)
            {
                m=m/10;
                count+=1;
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
public class Soln
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();

        for(int i=0;i<n;i++)
        {
            String  m=s.next();

            System.out.println(m.length());
        }
    }
}


import java.util.*;
public class Soln
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();

        for(int i=0;i<n;i++)
        {
            String  m=s.nextLine();

            System.out.println(m.length()-1);
        }
    }
}


import java.util.*;
public class Soln
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();

        for(int i=0;i<n;i++)
        {long count=0;
            long m=s.nextInt();
            while(m!=0)
            {
                m=m/10;
                count+=1;
            }
            System.out.println(count);
        }
    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
public class Main{
public static void main(String[] args)
{
 Scanner sc=new Scanner(System.in);
 int t=sc.nextInt();
 for(int l=0;l<t;l++)
 {
     String s=sc.next();
     BigInteger x=new BigInteger(s);
     StringBuilder str=new StringBuilder(s);
     str.reverse();
     BigInteger big=new BigInteger(str.toString());
     //System.out.println(big);
     String tmp=big.toString();
     StringBuilder str1=new StringBuilder(tmp);
     str1.reverse();
     BigInteger big1=new BigInteger(str1.toString());
     //System.out.println(big);
     BigInteger res=x.divide(big1);
     System.out.println(res);
 }
}
}


import java.util.*;
import java.lang.*;
import java.math.*;
public class Main{
public static void main(String[] args)
{
 Scanner sc=new Scanner(System.in);
 int t=sc.nextInt();
 for(int l=0;l<t;l++)
 {
     String s=sc.next();
     BigInteger x=new BigInteger(s);
     StringBuilder str=new StringBuilder(s);
     str.reverse();
     BigInteger big=new BigInteger(str.toString());
     //System.out.println(big);
     String tmp=big.toString();
     StringBuilder str1=new StringBuilder(tmp);
     str1.reverse();
     BigInteger big1=new BigInteger(str1.toString());
     //System.out.println(big);
     BigInteger res=x.divide(big1);
     System.out.println(s.length());
 }
}
}


import java.util.Arrays;
import java.util.Collections;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class struct
{

		public static void main (String[] args) {
		    Scanner sc=new Scanner(System.in);
		    int x=sc.nextInt();
		    int count=0;
		    sc.nextLine();
		   while(x>0) {
			   count=0;

			  String c=sc.nextLine();
			  System.out.println(c.length());

		   }

		}
}


import java.util.Arrays;
import java.util.Collections;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class struct
{

		public static void main (String[] args) {
		    Scanner sc=new Scanner(System.in);
		    int x=sc.nextInt();

		    sc.nextLine();
		   while(x>0) {

			  String c=sc.nextLine();
			  System.out.println(c.length());
				x--;
		   }

		}
}


import java.util.*;
import java.math.BigInteger;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int t = s.nextInt();
      while(t-->0){
          BigInteger n = s.nextBigInteger();
          System.out.println(n.toString().length());

      }
    }
}


import java.util.*;

import java.math.*;

public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		while(t-- != 0)
		{
			String s = cin.next();
			System.out.println(s.length());
		}
	}
}


import java.util.*;

import sun.security.krb5.internal.ccache.CCacheOutputStream;

import java.math.*;

public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		while(t-- != 0)
		{
			String s = cin.next();
			System.out.println(s.length());
		}
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int test=scan.nextInt();
		while(test>0) {
			String str=scan.next();
			System.out.println(str.length());
			test--;
		}
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int test=scan.nextInt();
		int n=scan.nextInt();
		while(test>0) {
			String str=scan.next();
			System.out.println(str.length());
			test--;
		}
	}
}


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

public class A implements Runnable {
    public static void main(String [] args) {
        new Thread(null, new A(), "whatever", 1<<26).start();
    }

    public void run() {

        FastScanner s = new FastScanner(System.in);
        StringBuilder sb = new StringBuilder();

        int t = s.nextInt();
        for (int i = 0; i < t; i++) {
            String str = s.next();
            sb.append(str.length() + "\n");
        }
        System.out.print(sb);
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner(InputStream in) {
            this(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() { return Double.parseDouble(next());}

    }
}