//#pragma comment(linker, "/STACK:60000000")

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define fs first
#define sc second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin());
#define Find(x,y) ((int)x.find(y))

//For debugging
#define debug_array(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debug_matrix(mat,row,col) for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
ll toInt(string s){ll r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
ll BigMod(ll B,ll P,ll M){  ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){ll i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct edge{ int cost,node; edge(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const edge &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(edge a,edge b){ return a.cost < b.cost;} //Asc Sort by cost

#define INF (1<<28)
#define SIZE 1000100

#define STATE_SIZE 2*SIZE

struct state
{
    int len,link,visit,cnt;
    map<char,int>child;
};

state T[STATE_SIZE];
char temp[SIZE];
int sz,last;
string str;

void Initialize(int N)
{
    int i;
    REP(i,2*N)
    {
        T[i].len=T[i].visit=0;
        T[i].link=-1;
        T[i].child.clear();
    }
    sz=1;
    last=0;
}

void add_char(char ch)
{
    int cur=sz++;
    T[cur].len=T[last].len+1;
    T[cur].cnt=1;

    int p;
    for(p=last; p!=-1 && T[p].child[ch]==0;p=T[p].link)
        T[p].child[ch]=cur;
    if(p==-1)
        T[cur].link=0;
    else
    {
        int q=T[p].child[ch];
        if(T[p].len+1==T[q].len)
            T[cur].link=q;
        else
        {
            int clone=sz++;
            T[clone].link=T[q].link;
            T[clone].len=T[p].len+1;
            T[clone].child=T[q].child;
            for(p=p;p!=-1 && T[p].child[ch]==q;p=T[p].link)
                T[p].child[ch]=clone;
            T[cur].link=T[q].link=clone;
        }
    }
    last=cur;
}

vector<int>GraphByLen[SIZE];

void DP_Processing()
{
    int i,j,u;

    REP(i,SZ(str)+1) GraphByLen[i].clear();
    REP(i,sz) GraphByLen[T[i].len].pb(i);

    for(i=SZ(str);i>=1;i--)
    {
        REP(j,SZ(GraphByLen[i]))
        {
            u=GraphByLen[i][j];
            T[T[u].link].cnt+=T[u].cnt;
        }
    }
}
char ch;
int solve(string s,int VisitNo)
{
    int L,R,cur,len=SZ(s),ans,last,l,i,p;

    s=s+s;
    last=l=ans=0;
    REP(i,SZ(s))
    {
        ch=s[i];
        if(T[last].child[ch])
        {
            last=T[last].child[ch];
            l++;
            if(l==len)
            {
                if(T[last].visit!=VisitNo)
                {
                    ans+=T[last].cnt;
                    T[last].visit=VisitNo;
                }
                if(T[T[last].link].len==l-1)
                    last=T[last].link;
                l--;
            }
        }
        else
        {
            p=T[last].link;
            while(p!=0 && T[p].child[ch]==0)
                p=T[p].link;
            if(T[p].child[ch])
                l=T[p].len+1;
            else l=0;
            last=T[p].child[ch];
        }
    }

    return ans;
}

string s;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);

    int i,j,test,Case=1,Q,ans;

    while(scanf("%s",temp)==1)
    {
        str=temp;
        Initialize(SZ(str));
        REP(i,SZ(str)) add_char(str[i]);
        DP_Processing();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%s",temp);
            s=temp;
            ans=solve(s,Case++);
            printf("%d\n",ans);
        }
    }

    return 0;
}

/*
bbbbbbbbbbbbbbb
5
ba
bbb
bbbbbb
bbb
b
*/


//#pragma comment(linker, "/STACK:60000000")

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define fs first
#define sc second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin());
#define Find(x,y) ((int)x.find(y))

//For debugging
#define debug_array(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debug_matrix(mat,row,col) for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
ll toInt(string s){ll r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
ll BigMod(ll B,ll P,ll M){  ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){ll i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct edge{ int cost,node; edge(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const edge &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(edge a,edge b){ return a.cost < b.cost;} //Asc Sort by cost

#define INF (1<<28)
#define SIZE 1000100

#define STATE_SIZE 2*SIZE

struct state
{
    int len,link,visit,cnt;
    map<char,int>child;
};

state T[STATE_SIZE];
char temp[SIZE];
int sz,last;
string str;

void Initialize(int N)
{
    int i;
    REP(i,2*N)
    {
        T[i].len=T[i].visit=0;
        T[i].link=-1;
        T[i].child.clear();
    }
    sz=1;
    last=0;
}

void add_char(char ch)
{
    int cur=sz++;
    T[cur].len=T[last].len+1;
    T[cur].cnt=1;

    int p;
    for(p=last; p!=-1 && T[p].child[ch]==0;p=T[p].link)
        T[p].child[ch]=cur;
    if(p==-1)
        T[cur].link=0;
    else
    {
        int q=T[p].child[ch];
        if(T[p].len+1==T[q].len)
            T[cur].link=q;
        else
        {
            int clone=sz++;
            T[clone].link=T[q].link;
            T[clone].len=T[p].len+1;
            T[clone].child=T[q].child;
            for(p=p;p!=-1 && T[p].child[ch]==q;p=T[p].link)
                T[p].child[ch]=clone;
            T[cur].link=T[q].link=clone;
        }
    }
    last=cur;
}

vector<int>GraphByLen[SIZE];

void DP_Processing()
{
    int i,j,u;

    REP(i,SZ(str)+1) GraphByLen[i].clear();
    REP(i,sz) GraphByLen[T[i].len].pb(i);

    for(i=SZ(str);i>=1;i--)
    {
        REP(j,SZ(GraphByLen[i]))
        {
            u=GraphByLen[i][j];
            T[T[u].link].cnt+=T[u].cnt;
        }
    }
}

int solve(string s,int VisitNo)
{
    int L,R,cur,len=SZ(s),ans,last,l,i,p;

    s=s+s;
    last=l=ans=0;
    REP(i,SZ(s))
    {
        char ch=s[i];
        if(T[last].child[ch]!=0)
        {
            last=T[last].child[ch];
            l++;
            if(l==len)
            {
                if(T[last].visit!=VisitNo)
                {
                    ans+=T[last].cnt;
                    T[last].visit=VisitNo;
                }
                if(T[T[last].link].len==len-1)
                    last=T[last].link;
                l--;
            }
        }
        else
        {
            p=T[last].link;
            while(p!=0 && T[p].child[ch]==0)
                p=T[p].link;
            if(T[p].child[ch])
                l=T[p].len+1;
            else l=0;
            last=T[p].child[ch];
        }
    }

    return ans;
}

string s;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);

    int i,j,test,Case=1,Q,ans;

    while(scanf("%s",temp)==1)
    {
        str=temp;
        Initialize(SZ(str));
        REP(i,SZ(str)) add_char(str[i]);
        DP_Processing();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%s",temp);
            s=temp;
            ans=solve(s,Case++);
            printf("%d\n",ans);
        }
    }

    return 0;
}

/*
bbbbbbbbbbbbbbb
5
ba
bbb
bbbbbb
bbb
b
*/


//#pragma comment(linker, "/STACK:60000000")

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define fs first
#define sc second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin());
#define Find(x,y) ((int)x.find(y))

//For debugging
#define debug_array(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debug_matrix(mat,row,col) for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
ll toInt(string s){ll r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
ll BigMod(ll B,ll P,ll M){  ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){ll i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct edge{ int cost,node; edge(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const edge &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(edge a,edge b){ return a.cost < b.cost;} //Asc Sort by cost

#define INF (1<<28)
#define SIZE 1000100

#define STATE_SIZE 2*SIZE

struct state
{
    int len,link,visit,cnt;
    map<char,int>child;
};

state T[STATE_SIZE];
char temp[SIZE];
int sz,last;
string str;

void Initialize(int N)
{
    int i;
    REP(i,2*N)
    {
        T[i].len=T[i].visit=0;
        T[i].link=-1;
        T[i].child.clear();
    }
    sz=1;
    last=0;
}

void add_char(char ch)
{
    int cur=sz++;
    T[cur].len=T[last].len+1;
    T[cur].cnt=1;

    int p;
    for(p=last; p!=-1 && T[p].child[ch]==0;p=T[p].link)
        T[p].child[ch]=cur;
    if(p==-1)
        T[cur].link=0;
    else
    {
        int q=T[p].child[ch];
        if(T[p].len+1==T[q].len)
            T[cur].link=q;
        else
        {
            int clone=sz++;
            T[clone].link=T[q].link;
            T[clone].len=T[p].len+1;
            T[clone].child=T[q].child;
            for(p=p;p!=-1 && T[p].child[ch]==q;p=T[p].link)
                T[p].child[ch]=clone;
            T[cur].link=T[q].link=clone;
        }
    }
    last=cur;
}

vector<int>GraphByLen[SIZE];

void DP_Processing()
{
    int i,j,u;

    REP(i,SZ(str)+1) GraphByLen[i].clear();
    REP(i,sz) GraphByLen[T[i].len].pb(i);

    for(i=SZ(str);i>=1;i--)
    {
        REP(j,SZ(GraphByLen[i]))
        {
            u=GraphByLen[i][j];
            T[T[u].link].cnt+=T[u].cnt;
        }
    }
}

int solve(string s,int VisitNo)
{
    int L,R,cur,len=SZ(s),ans;

    s=s+s;
    L=R=cur=ans=0;
    while(R<SZ(s) && L<=R)
    {
        while(R<SZ(s) && R-L<len)
        {
            if(T[cur].child[s[R]]==0) break;
            cur=T[cur].child[s[R]];
            R++;
        }
        if(R-L==len)
        {
            if(T[cur].visit!=VisitNo)
            {
                T[cur].visit=VisitNo;
                ans+=T[cur].cnt;
            }
        }
        if(cur!=0 && T[T[cur].link].len==(R-L-1))
            cur=T[cur].link;
        L++;
    }
    return ans;
}

string s;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);

    int i,j,test,Case=1,Q,ans;

    while(scanf("%s",temp)==1)
    {
        str=temp;
        Initialize(SZ(str));
        REP(i,SZ(str)) add_char(str[i]);
        DP_Processing();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%s",temp);
            s=temp;
            ans=solve(s,Case++);
            printf("%d\n",ans);
        }
    }

    return 0;
}

/*
bbbbbbbbbbbbbbb
5
ba
bbb
bbbbbb
bbb
b
*/


//#pragma comment(linker, "/STACK:60000000")

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define fs first
#define sc second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin());
#define Find(x,y) ((int)x.find(y))

//For debugging
#define debug_array(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debug_matrix(mat,row,col) for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
ll toInt(string s){ll r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){	ll R=1;	while(P>0)	{if(P%2==1)	R=(R*B);P/=2;B=(B*B);}return R;}
ll BigMod(ll B,ll P,ll M){	ll R=1;	while(P>0)	{if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}	return R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){ll i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct edge{ int cost,node; edge(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const edge &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(edge a,edge b){ return a.cost < b.cost;} //Asc Sort by cost

#define INF (1<<28)
#define SIZE 1000100

#define STATE_SIZE 2*SIZE

struct state
{
    int len,link,visit,cnt;
    map<char,int>child;
};

state T[STATE_SIZE];
char temp[SIZE];
int sz,last;
string str;

void Initialize(int N)
{
    int i;
    REP(i,2*N)
    {
        T[i].len=T[i].visit=0;
        T[i].link=-1;
        T[i].child.clear();
    }
    sz=1;
    last=0;
}

void add_char(char ch)
{
    int cur=sz++;
    T[cur].len=T[last].len+1;
    T[cur].cnt=1;

    int p;
    for(p=last; p!=-1 && T[p].child[ch]==0;p=T[p].link)
        T[p].child[ch]=cur;
    if(p==-1)
        T[cur].link=0;
    else
    {
        int q=T[p].child[ch];
        if(T[p].len+1==T[q].len)
            T[cur].link=q;
        else
        {
            int clone=sz++;
            T[clone].link=T[q].link;
            T[clone].len=T[p].len+1;
            T[clone].child=T[q].child;
            for(p=p;p!=-1 && T[p].child[ch]==q;p=T[p].link)
                T[p].child[ch]=clone;
            T[cur].link=T[q].link=clone;
        }
    }
    last=cur;
}

vector<int>GraphByLen[SIZE];

void DP_Processing()
{
    int i,j,u;

    REP(i,SZ(str)+1) GraphByLen[i].clear();
    REP(i,sz) GraphByLen[T[i].len].pb(i);

    for(i=SZ(str);i>=1;i--)
    {
        REP(j,SZ(GraphByLen[i]))
        {
            u=GraphByLen[i][j];
            T[T[u].link].cnt+=T[u].cnt;
        }
    }
}

int solve(string s,int VisitNo)
{
    int L,R,cur,len=SZ(s),ans;

    s=s+s;
    L=R=cur=ans=0;
    while(R<SZ(s) && L<=R)
    {
        while(R<SZ(s) && R-L<len)
        {
            if(T[cur].child[s[R]]==0) break;
            cur=T[cur].child[s[R]];
            R++;
        }
        if(R-L==len)
        {
            if(T[cur].visit!=VisitNo)
            {
                T[cur].visit=VisitNo;
                ans+=T[cur].cnt;
            }
        }
        if(cur!=0 && T[T[cur].link].len==(R-L-1))
            cur=T[cur].link;
        L++;
    }
    return ans;
}

string s;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);

    int i,j,test,Case=1,Q,ans;

    while(scanf("%s",temp)==1)
    {
        str=temp;
        Initialize(SZ(str));
        REP(i,SZ(str)) add_char(str[i]);
        DP_Processing();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%s",temp);
            s=temp;
            ans=solve(s,Q);
            printf("%d\n",ans);
        }
    }

    return 0;
}


//#pragma comment(linker, "/STACK:60000000")

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define fs first
#define sc second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin());
#define Find(x,y) ((int)x.find(y))

//For debugging
#define debug_array(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debug_matrix(mat,row,col) for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
ll toInt(string s){ll r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
ll BigMod(ll B,ll P,ll M){  ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){ll i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct edge{ int cost,node; edge(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const edge &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(edge a,edge b){ return a.cost < b.cost;} //Asc Sort by cost

#define INF (1<<28)
#define SIZE 1000100

#define STATE_SIZE 2*SIZE

struct state
{
    int len,link,visit,cnt;
    map<char,int>child;
};

state T[STATE_SIZE];
char temp[SIZE];
int sz,last;
string str;

void Initialize(int N)
{
    int i;
    REP(i,2*N)
    {
        T[i].len=T[i].visit=0;
        T[i].link=-1;
        T[i].child.clear();
    }
    sz=1;
    last=0;
}

void add_char(char ch)
{
    int cur=sz++;
    T[cur].len=T[last].len+1;
    T[cur].cnt=1;

    int p;
    for(p=last; p!=-1 && T[p].child[ch]==0;p=T[p].link)
        T[p].child[ch]=cur;
    if(p==-1)
        T[cur].link=0;
    else
    {
        int q=T[p].child[ch];
        if(T[p].len+1==T[q].len)
            T[cur].link=q;
        else
        {
            int clone=sz++;
            T[clone].link=T[q].link;
            T[clone].len=T[p].len+1;
            T[clone].child=T[q].child;
            for(p=p;p!=-1 && T[p].child[ch]==q;p=T[p].link)
                T[p].child[ch]=clone;
            T[cur].link=T[q].link=clone;
        }
    }
    last=cur;
}

vector<int>GraphByLen[SIZE];

void DP_Processing()
{
    int i,j,u;

    REP(i,SZ(str)+1) GraphByLen[i].clear();
    REP(i,sz) GraphByLen[T[i].len].pb(i);

    for(i=SZ(str);i>=1;i--)
    {
        REP(j,SZ(GraphByLen[i]))
        {
            u=GraphByLen[i][j];
            T[T[u].link].cnt+=T[u].cnt;
        }
    }
}
char ch;
int solve(string s,int VisitNo)
{
    int L,R,cur,len=SZ(s),ans,last,l,i,p;

    s=s+s;
    last=l=ans=0;
    REP(i,SZ(s))
    {
        ch=s[i];
        if(T[last].child[ch])
        {
            last=T[last].child[ch];
            l++;
            if(l==len)
            {
                if(T[last].visit!=VisitNo)
                {
                    ans+=T[last].cnt;
                    T[last].visit=VisitNo;
                }
                if(T[T[last].link].len==l-1)
                    last=T[last].link;
                l--;
            }
        }
        else
        {
            p=T[last].link;
            while(p!=-1 && T[p].child[ch]==0)
                p=T[p].link;
            if(p==-1)
                last=l=0;
            else
            {
                last=T[p].child[ch];
                l=T[p].len+1;
            }
        }
    }

    return ans;
}

string s;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);

    int i,j,test,Case=1,Q,ans;

    while(scanf("%s",temp)==1)
    {
        str=temp;
        Initialize(SZ(str));
        REP(i,SZ(str)) add_char(str[i]);
        DP_Processing();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%s",temp);
            s=temp;
            ans=solve(s,Case++);
            printf("%d\n",ans);
        }
    }

    return 0;
}

/*
bbbbbbbbbbbbbbb
5
ba
bbb
bbbbbb
bbb
b
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 500005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
	 int vis[N<<1];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(par[now]));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[p] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	//for(int i = 0; i < sz; i++) cout<< par[i] <<" "; cout<< endl;
	//for(int i = 0; i < sz; i++) cout<< val[i] <<" "; cout<< endl;
	//for(int i = 0; i < sz; i++) cout<< G[i][0] <<" "<< G[i][1]<<endl;
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			if(0 == G[now][x]) {
				while(now && 0 == G[now][x]) {now = par[now]; len = val[now]; }
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && n >= mn && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	for(int tmp = 1 ; tmp <= t; tmp ++){
		scanf("%s",c);
		int m = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*m-1; i++){
			int x = c[i%m] - 'a';
			/*
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > m) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
			*/
			while(now != -1 && ! G[now][x]) now = par[now], len = now == -1 ? 0 : val[now];
			if(now == -1) now = len = 0;
			else len ++ , now = G[now][x];
			while(par[now] >= 0 && val[par[now]] >= len) now = par[now], len = val[now];
			if(len >= m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 500005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(par[now]));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 1000005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
//	for(int i = 0; i < sz; i++) cout<< G[i][0] << " "<< G[i][1] << endl;
	cin >> t;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	for(int tmp = 1 ; tmp <= t; tmp ++){
		scanf("%s",c);
		int m = strlen(c);
		int len = 0, now = 0, ans = 0;
		for(int i = 0;i < 2*m-1; i++){
			int x = c[i%m] - 'a';
			///*
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > m) {
					//if(now == 0 || par[now] == 0) break;
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//*/
			/*
			while(now != -1 && 0 == G[now][x]) now = par[now], len = (now == -1 ? 0 : val[now]);
			if(now == -1) now = len = 0;
			else len ++ , now = G[now][x];
			while(par[now] != -1 && val[par[now]] >= len) now = par[now], len = val[now];
			if(len >= m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
			*/
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 500005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int vis[N<<1];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				assert(fit(par[now]));
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(par[now]));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				assert(fit(now));
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 500005;
// sam
bool fit(int x){return x >=0 && x < 200005;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int vis[N<<1];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				assert(fit(par[now]));
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(par[now]));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				assert(fit(now));
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	//for(int i = 0; i < sz; i++) cout<< par[i] <<" "; cout<< endl;
	//for(int i = 0; i < sz; i++) cout<< val[i] <<" "; cout<< endl;
	//for(int i = 0; i < sz; i++) cout<< G[i][0] <<" "<< G[i][1]<<endl;
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			if(0 == G[now][x]) {
				while(now && 0 == G[now][x]) {now = par[now]; len = val[now]; }
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && n >= mn && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	while(1);
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(now));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
bool fit(int x){return x >=0 && x < N*2;}
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	assert(fit(np));
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			assert(fit(nq));
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 1;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int n = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*n-1; i++){
			int x = c[i%n] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > n) {
					now = par[now];
					assert(fit(par[now]));
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=n && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	for(int tmp = 1 ; tmp <= t; tmp ++){
		scanf("%s",c);
		int m = strlen(c);
		int len = 0, now = 0, ans = 0;
		for(int i = 0;i < 2*m-1; i++){
			int x = c[i%m] - 'a';
			///*
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > m) {
					if(now == 0 || par[now] == 0) break;
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
			//*/
			/*
			while(now != -1 && 0 == G[now][x]) now = par[now], len = (now == -1 ? 0 : val[now]);
			if(now == -1) now = len = 0;
			else len ++ , now = G[now][x];
			while(par[now] >= 0 && val[par[now]] >= len) now = par[now], len = val[now];
			if(len >= m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			*/
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 0;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int m = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*m-1; i++){
			if(val[0])while(1);
			int x = c[i%m] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > m) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
const int N = 100005;
// sam
int par[N<<1], G[N<<1][26], val[N<<1], sz, cnt[N<<1], last;
struct node{
	int val,id;
	bool operator < (const node a) const{
		return val > a.val;
	}
} num[N<<1];
void ins(int x){
	int p = last, np = sz ++;
	val[np] = val[p] + 1;
	while(p!= -1 && 0 == G[p][x]) G[p][x] = np, p = par[p];
	if( -1 == p ) par[np] = 0;
	else {
		int q = G[p][x];
		if(val[p] + 1 == val[q]) {
			par[np]= q;
		} else {
			int nq = sz ++;
			memcpy(G[nq],G[q],sizeof(G[q]));
			val[nq] = val[p] + 1;
			par[nq] = par[q];
			par[q] = nq;
			par[np] = nq;
			while(-1 != p && G[p][x] == q) G[p][x] = nq, p = par[p];
		}
	}
	last = np ;
}
// solve
char ch[N],c[N*10];
int main(){
	scanf("%s",ch);
	int n = strlen(ch);
	par[last = 0] = -1;
	sz = 1;
	for(int i = 0;i < n; i++) {
		ins(ch[i] - 'a');
	}
	for(int i = 0; i < sz; i++) num[i].id = i, num[i].val = val[i];
	sort(num,num+sz);
	int t = last,v;
	while(t) cnt[t]= 1, t = par[t];
	for(int i = 0; i < sz; i++){
		int u = num[i].id;
		for(int j = 0; j < 26; j++) if(v = G[u][j]) {
			cnt[u] += cnt[v];
		}
	}
	cin >> t;
	int tmp = 0;
	static int vis[N<<1];
	memset(vis,0,sizeof(vis));
	while(t --){
		tmp++;
		scanf("%s",c);
		int m = strlen(c);
		int len = 0, now = 0; long long ans = 0;
		for(int i = 0;i < 2*m-1; i++){
			int x = c[i%m] - 'a';
			while(now && 0 == G[now][x]) {
				now = par[now]; len = val[now];
			}
			if(G[now][x]){
				now = G[now][x];
				len ++;
				int mn = val[par[now]] + 1;
				while(mn > m) {
					now = par[now];
					len = val[now];
					mn = val[par[now]] + 1;
				}
				//cout<< mn<<" "<<val[now]<<endl;
				if(len>=m && vis[now] != tmp) ans += cnt[now], vis[now] = tmp;
			}
			//cout << c[i%n] <<" "<< now <<" "<< ans<<endl;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>

#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;

using namespace std;

const int LEN = 2e6 + 5, MAXS = 2 * LEN, K = 26;
int go[MAXS][K], slink[MAXS], length[MAXS], cnt[MAXS], clone[MAXS], final[MAXS], p, q, size = 2, last = 1;
char s[LEN], t[LEN];

void extend (int c)
{
	for (p = last; !go[p][c]; p = slink[p])
	    go[p][c] = size;

	q = go[p][c];
	length[size] = length[last] + 1;
	cnt[size] = 1;
	last = size++;

	if (!p)
	    slink[last] =  1;
	else if (length[p] + 1 == length[q])
		slink[last] = q;
	else
	{
		for (length[size] = length[p] + 1; go[p][c] == q; p = slink[p])
		    go[p][c] = size;

		clone[size] = true;
		memcpy(go[size], go[q], sizeof go[size]);
		slink[size] = slink[q];
		slink[last] = slink[q] = size++;
	}
}

void build ()
{
	fill(go[0], go[0] + K, 1);
	length[0] = -1;

	for (int i = 0; s[i]; ++i)
	    extend(s[i] - 'a');

	for (; last > 0; last = slink[last])
		final[last] = 1;
}

int used[MAXS];

int check (int st, int m, int q)
{
	for (; st && length[slink[st]] >= m; st = slink[st]);

	if (used[st] == q)
		return 0;

	used[st] = q;
	return cnt[st];
}

int lcs ()
{
	static int q = 1;
	int ans = 0;
	int m = strlen(t);
	memcpy(t + m, t, m);
	t[m + m] = 0;

	for (int i = 0, len = 0, st = 1; t[i]; ++i)
	{
		char c = t[i] - 'a';

		if (!go[st][c])
		{
			for (; !go[st][c]; st = slink[st]);

			len = length[st];
		}

		st = go[st][c];

		if (++len >= m)
			ans += check(st, m, q);
	}

	++q;
	return ans;
}

int n, id[MAXS];

bool cmp (int i, int j)
{
	return length[i] < length[j];
}

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

	cin >> s;
	build();

	for (int i = 0; i < size; ++i)
		id[i] = i;

	sort(id, id + size, cmp);

	for (int i = size - 1; i > 0; --i)
	{
		int st = id[i];
		cnt[slink[st]] += cnt[st];
	}

	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> t;
		cout << lcs() << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;

using namespace std;

const int LEN = 2e6 + 5, MAXS = 2 * LEN, K = 26;
int go[MAXS][K], slink[MAXS], length[MAXS], cnt[MAXS], clone[MAXS], final[MAXS], p, q, size = 2, last = 1;
char s[LEN], t[LEN];

void extend (int c)
{
	for (p = last; !go[p][c]; p = slink[p])
	    go[p][c] = size;

	q = go[p][c];
	length[size] = length[last] + 1;
	cnt[size] = 1;
	last = size++;

	if (!p)
	    slink[last] =  1;
	else if (length[p] + 1 == length[q])
		slink[last] = q;
	else
	{
		for (length[size] = length[p] + 1; go[p][c] == q; p = slink[p])
		    go[p][c] = size;

		clone[size] = true;
		memcpy(go[size], go[q], sizeof go[size]);
		slink[size] = slink[q];
		slink[last] = slink[q] = size++;
	}
}

void build ()
{
	fill(go[0], go[0] + K, 1);
	length[0] = -1;

	for (int i = 0; s[i]; ++i)
	    extend(s[i] - 'a');

	for (; last > 0; last = slink[last])
		final[last] = 1;
}

int used[MAXS];

int it = 0;

int check (int st, int m, int q)
{
	for (; st && length[slink[st]] >= m; st = slink[st])
	{
		if (used[st] == q)
			return 0;

		used[st] = q;
		++it;
	}

	if (used[st] == q)
		return 0;

	used[st] = q;
	return cnt[st];
}

int lcs ()
{
	static int q = 1;
	int ans = 0;
	int m = strlen(t);
	memcpy(t + m, t, m);
	t[m + m] = 0;

	for (int i = 0, len = 0, st = 1; t[i]; ++i)
	{
		char c = t[i] - 'a';

		if (!go[st][c])
		{
			for (; !go[st][c]; st = slink[st]);

			len = length[st];
		}

		st = go[st][c];

		if (++len >= m)
			ans += check(st, m, q);
	}

	++q;
	return ans;
}

int n, id[MAXS];

bool cmp (int i, int j)
{
	return length[i] < length[j];
}

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

	cin >> s;
	//int N = 1e3;
//	for (int i = 0; i < N; ++i)
//		s[i] = 'a';

	build();

	for (int i = 0; i < size; ++i)
		id[i] = i;

	sort(id, id + size, cmp);

	for (int i = size - 1; i > 0; --i)
	{
		int st = id[i];
		cnt[slink[st]] += cnt[st];
	}

	cin >> n;
	//n = 1;

	for (int i = 0; i < n; ++i)
	{
		cin >> t;

		//for (int i = 0; i < N / 2; ++i)
//			t[i] = 'a';
		cout << lcs() << '\n';
	}

	//DB(it);
	return 0;
}


#include<stdio.h>
int a[100005];
long long int b[10000005] = { 0 };
int main() {
	int n, x;
	long long int sum = 0;
	scanf_s("%d%d",&n, &x);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
		b[a[i] ^ x]++;
	}
	for (int i = 0; i < n; i++) {
		sum += b[a[i]];
	}
	sum /= 2;
	printf("%I64d", sum);
	return 0;

}


#include<stdio.h>
int a[100005];
long long int b[10000005] = { 0 };
int main() {
	int n, x;
	long long int sum = 0;
	scanf_s("%d%d",&n, &x);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
		b[a[i] ^ x]++;
	}
	if (x = 0) {
		for (int i = 0; i < 0; i++) {
			sum += b[a[i]] - 1;
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			sum += b[a[i]];
		}
	}
	sum /= 2;
	printf("%I64d", sum);
	return 0;

}


#include<stdio.h>
int a[100005];
long long int b[10000005] = { 0 };
int main() {
	int n, x;
	long long int sum = 0;
	scanf_s("%d%d",&n, &x);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
		b[a[i] ^ x]++;
	}
	if (x == 0) {
		for (int i = 0; i < 0; i++) {
			sum += b[a[i]] - 1;
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			sum += b[a[i]];
		}
	}
	sum /= 2;
	printf("%I64d", sum);
	return 0;

}


#include<stdio.h>
int a[100005];
long long int b[10000005] = { 0 };
int main() {
	int n, x;
	long long int sum = 0;
	scanf_s("%d%d",&n, &x);
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
		b[a[i] ^ x]++;
	}
	if (x == 0) {
		for (int i = 0; i < n; i++) {
			sum += b[a[i]] - 1;
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			sum += b[a[i]];
		}
	}
	sum /= 2;
	printf("%I64d", sum);
	return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include <map>
#include <limits>
#include <set>
#include <algorithm>

using namespace std;

int arr[100001];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, x, ans = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		int val;
		cin >> val;
		ans += arr[val^x];
		arr[val]++;
	}
	cout << ans;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include <map>
#include <limits>
#include <set>
#include <algorithm>

using namespace std;

int arr[10000001];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long long int n, x, ans = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		long long int val;
		cin >> val;
		ans += arr[val^x];
		arr[val]++;
	}
	cout << ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include <map>
#include <limits>
#include <set>
#include <algorithm>

using namespace std;

int arr[10000001];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, x, ans = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		int val;
		cin >> val;
		ans += arr[val^x];
		arr[val]++;
	}
	cout << ans;

}


#include <iostream>
using namespace std;
#define int1 long long
int main() {
	// your code goes here
	int1 n,x;
	cin>>n>>x;
	int1 *a=new int1[n];
	int1 *count=new int1[100001];
	for(int1 i=0;i<100001;i++)
	{
	   count[i]=0;
	}
	for(int1 i=0;i<n;i++)
	{
	    cin>>a[i];
	    count[a[i]]+=1;
	}
	long long m=0;
	for(int1 i=0;i<100001;i++)
	{
	    if(count[i]>=1)
	    {
	        int1 y=(x^i);
            if(y>100000)
              continue;
	        if(count[y]>=1)
	        {
	             //cout<<y<<" "<<i<<" ";
	            // cout<<count[y]<<" "<<count[i]<<" ";
	             if(y==i)
		         {
		            m+=(count[y]*(count[y]-1))/2;
		         }
			     else if(y>i)
				 {
                    if(count[i]%2!=0&&count[y]%2==0)
                    {
                        m+=count[y]*(count[i]+1)/2;
                    }
                    else
		            m+=(count[i]*(count[y]+1)/2);
			     }
			     else
			     {
                      if(count[i]%2==0&&count[y]%2!=0)
                      {
                           m+=count[i]*(count[y]-1)/2;
                      }
                     else
	                  m+=(count[y]*(count[i]-1)/2);
	             }
	             //cout<<m<<endl;
	        }
	    }
	}
	cout<<m<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int *a=new int[n];
    for(int i=0;i<n;i++)
     cin>>a[i];
    sort(a,a+n);
    long long m=0;
    for(int i=0;i<n-1;i++)
    {
        int y=(x^(a[i]));
        //cout<<y<<endl;
        int l=i+1;
        int r=n-1;
        while( l <= r )
        {
          //cout<<a[l]<<" "<<a[r]<<endl;
          int mid = l + (r-l)/2;
          if( a[mid] == y) // first comparison
          {
              //cout<<a[mid]<<" yes"<<endl;
              m++;
           }
         if( a[mid] < y ) // second comparison
              l= mid+1;
         else
             r=mid - 1;
         }

    }
    cout<<m<<endl;
return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int Binary(int a[],int l ,int r,int y)
{
          int m=0;
          if(l>r)
              return m;
          int mid = l + (r-l)/2;
          if( a[mid] == y) // first comparison
          {
              return 1+Binary(a,l,mid-1,y)+Binary(a,mid+1,r,y);
          }
          if( a[mid] < y ) // second comparison
             return Binary(a,mid+1,r,y);
          else
             return Binary(a,l,mid-1,y);
return 0;
}
int main()
{
    int n,x;
    cin>>n>>x;
    int *a=new int[n];
    for(int i=0;i<n;i++)
     cin>>a[i];
    sort(a,a+n);
    long long m=0;
    for(int i=0;i<n-1;i++)
    {
        int y=(x^(a[i]));
        int l=i+1;
        int r=n-1;
        m=m+Binary(a,l,r,y);
    }
    cout<<m<<endl;
return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,x;
	cin>>n>>x;
	int *a=new int [n];
	int *count=new int[100001];
	for(int i=0;i<100001;i++)
	{
	   count[i]=0;
	}
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    count[a[i]]+=1;
	}
	long long m=0;
	for(int i=0;i<100001;i++)
	{
	    if(count[i]>=1)
	    {
	        int y=(x^i);
	        if(count[y]>=1)
	        {
	             //cout<<y<<" "<<i<<endl;
	             //cout<<count[y]<<" "<<count[i]<<endl;
	             if(y==i)
		         {
		            m+=(count[y]*(count[y]-1))/2;
		         }
			     else if(y>i)
				 {
		            m+=(count[i]*(count[y]+1)/2);
			     }
			     else
			     {
	                  m+=(count[y]*(count[i]-1)/2);
	             }
	             //cout<<m<<endl;
	        }
	    }
	}
	cout<<m<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,x;
	cin>>n>>x;
	int *a=new int [n];
	int *count=new int[100001];
	for(int i=0;i<100001;i++)
	{
	   count[i]=0;
	}
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    count[a[i]]+=1;
	}
	long long m=0;
	for(int i=0;i<100001;i++)
	{
	    if(count[i]>=1)
	    {
	        int y=(x^i);
	        if(count[y]>=1)
	        {
	             if(y==i)
		         {
		            m+=(count[y]*(count[y]-1))/2;
		         }
			     else if(y>i)
				 {
		            m+=(count[y]*(count[i]+1)/2);
			     }
			     else
			     {
	                  m+=(count[y]*(count[i]-1)/2);
	             }
	        }
	    }
	}
	cout<<m<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
   int n,x;
   cin>>n>>x;
   int *a=new int[n];
   for(int i=0;i<n;i++)
      cin>>a[i];
   long long m=0;
   for(int i=0;i<n-1;i++)
   {
      for(int j=i+1;j<n;j++)
      {
          if((a[i]^a[j])==x)
            m++;
      }
   }
   cout<<m<<endl;
return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,x;
	cin>>n>>x;
	int *a=new int [n];
	int *count=new int[100001];
	for(int i=0;i<100001;i++)
	{
	   count[i]=0;
	}
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    count[a[i]]+=1;
	}
	long long m=0;
	for(int i=0;i<100001;i++)
	{
	    if(count[i]>=1)
	    {
	        int y=(x^i);
            if(y>100000)
              continue;
	        if(count[y]>=1)
	        {
	             //cout<<y<<" "<<i<<" ";
	            // cout<<count[y]<<" "<<count[i]<<" ";
	             if(y==i)
		         {
		            m+=(count[y]*(count[y]-1))/2;
		         }
			     else if(y>i)
				 {
                    if(count[i]%2!=0&&count[y]%2==0)
                    {
                        m+=count[y]*(count[i]+1)/2;
                    }
                    else
		            m+=(count[i]*(count[y]+1)/2);
			     }
			     else
			     {
                      if(count[i]%2==0&&count[y]%2!=0)
                      {
                           m+=count[i]*(count[y]-1)/2;
                      }
                     else
	                  m+=(count[y]*(count[i]-1)/2);
	             }
	             //cout<<m<<endl;
	        }
	    }
	}
	cout<<m<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,x;
	cin>>n>>x;
	int *a=new int [n];
	int *count=new int[100001];
	for(int i=0;i<100001;i++)
	{
	   count[i]=0;
	}
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    count[a[i]]+=1;
	}
	long long m=0;
	for(int i=0;i<100001;i++)
	{
	    if(count[i]>=1)
	    {
	        int y=(x^i);
	        if(count[y]>=1)
	        {
	             //cout<<y<<" "<<i<<" ";
	            // cout<<count[y]<<" "<<count[i]<<" ";
	             if(y==i)
		         {
		            m+=(count[y]*(count[y]-1))/2;
		         }
			     else if(y>i)
				 {
                    if(count[i]%2!=0&&count[y]%2==0)
                    {
                        m+=count[y]*(count[i]+1)/2;
                    }
                    else
		            m+=(count[i]*(count[y]+1)/2);
			     }
			     else
			     {
                      if(count[i]%2==0&&count[y]%2!=0)
                      {
                           m+=count[i]*(count[y]-1)/2;
                      }
                     else
	                  m+=(count[y]*(count[i]-1)/2);
	             }
	             //cout<<m<<endl;
	        }
	    }
	}
	cout<<m<<endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#include <functional>

using namespace std;

int d[100010];
int ca[100010];

int main()
{
	int i, n, x, c;
	long long cnt = 0;
	cin >> n >> x;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &d[i]);
		ca[d[i]]++;
	}
	for (i = 1; i <= 100000; i++)
	{
		if (ca[i] >= 1)
		{
			c = x^i;
			if (c == i)
			{
				cnt += ((long long)ca[c] * ((long long)ca[c] - 1)) / 2;
			}
			else if (c > i)
			{
				cnt += ((long long)ca[c] * (long long)ca[i]);
			}
		}
	}
	cout << cnt;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#include <functional>

using namespace std;

long long ca[100010];

int main()
{
	int i, n;
	long long x;
	long long c, a;
	long long cnt = 0;
	cin >> n >> x;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a);
		ca[a]++;
	}
	for (i = 1; i <= 100000; i++)
	{
		if (ca[i] >= 1)
		{
			c = x^i;
			if (c == i)
			{
				cnt += (ca[c] * (ca[c] - 1)) / 2;
			}
			else if (c > i)
			{
				cnt += (ca[c] * ca[i]);
			}
		}
	}
	cout << cnt;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#include <functional>

using namespace std;

long long ca[100010];

int main()
{
	int i, n;
	long long x;
	long long c, a;
	long long cnt = 0;
	cin >> n >> x;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a);
		ca[a]++;
	}
	for (i = 1; i <= 100000; i++)
	{
		if (ca[i] >= 1)
		{
			c = x^i;
			if (c == i)
			{
				cnt += (ca[c] * (ca[c] - 1)) / 2;
			}
			else if (c > i)
			{
				if (c > 100000) continue;
				cnt += (ca[c] * ca[i]);
			}
		}
	}
	cout << cnt;
}


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#include <functional>

using namespace std;

long long ca[100010];

int main()
{
	int i, n, x, c, a;
	long long cnt = 0;
	cin >> n >> x;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a);
		ca[a]++;
	}
	for (i = 1; i <= 100000; i++)
	{
		if (ca[i] >= 1)
		{
			c = x^i;
			if (c == i)
			{
				cnt += (ca[c] * (ca[c] - 1)) / 2;
			}
			else if (c > i)
			{
				cnt += (ca[c] * ca[i]);
			}
		}
	}
	cout << cnt;
}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e6+1000;
int i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		if (j==a[i]) ot--;
		ot+=t[j];
	}
	cout<<ot/2;
    return 0;

}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e5;
int i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		if (j==a[i]) ot--;
		ot+=t[j];
	}
	cout<<ot/2;
    return 0;

}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e5+1000;
int i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		if (j==a[i]) ot--;
		ot+=t[j];
	}
	cout<<ot/2;
    return 0;

}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e6+1000;
__int64 i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		if (j==a[i]) ot--;
		ot+=t[j];
		t[a[i]]--;
	}
	cout<<ot;
    return 0;

}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e6+1000;
int i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		if (j==a[i]) ot--;
		ot+=t[j];
		t[a[i]]--;
	}
	cout<<ot;
    return 0;

}


#include "stdio.h"
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

const int w = (int) 1e5;
int i,j,n,x,ot;
int t[w], a[w];

int main()
{
	#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
	#endif

	cin>>n>>x;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		t[a[i]]++;
	}

	for (i=0;i<n;i++)
	{
		j = a[i] ^ x;
		ot+=t[j];
	}
	cout<<ot/2;
    return 0;

}


#include <iostream>

using namespace std;

long long arr[1000 * 100 + 10];

int main()
{
	long long ans = 0;
	long long n, x, a;
	cin >> n >> x;
	while (--n >= 0) {
		cin >> a;
		ans += arr[a^x];
		arr[a]++;
	}
	cout << ans<< endl;
    return 0;
}


#include <iostream>

using namespace std;

int arr[1000 * 100 + 10];

int main()
{
	long long ans = 0;
	int n, x, a;
	cin >> n >> x;
	while (--n >= 0) {
		cin >> a;
		ans += arr[a^x];
		arr[a]++;
	}
	cout << ans<< endl;
    return 0;
}


#include <iostream>

using namespace std;

long long arr[1000 * 200];

int main()
{
	long long ans = 0;
	long long n, x, a;
	cin >> n >> x;
	while (--n >= 0) {
		cin >> a;
		ans += arr[x^a];
		arr[a]++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
using namespace std;
int n, x, a[100002];
int main()
{
	long long ans=0;
	cin>>n>>x;
	for(int i=0; i<n; i++)
	{
		int k;
		cin>>k;
		ans+=a[x^k];
		a[k]++;
	}
	cout<<ans<<endl;
}


#include <iostream>
using namespace std;
int n, x, a[1000000];
int main()
{
	long long ans=0;
	cin>>n>>x;
	for(int i=0; i<n; i++)
	{
		int k;
		cin>>k;
		ans+=a[x^k];
		a[k]++;
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[10001],count=0;

int main() {
	std::cin >> n >> m;
	for (unsigned i = 0,help,help1; i < n; ++i) {
		std::cin >> help;
		++arr[help];
		help1 = (help^m);
		count +=  arr[help1];
	}

	/*for (unsigned i = 1,help; i <= 10000; ++i) {
		if (arr[i]) {
			help = (i ^ m);
			if (help>i)
				count += (arr[i] * arr[help]);

		}
	}*/

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[10000],count=0;

bool b(unsigned *arr, unsigned size, unsigned m) {

	unsigned left = 0, right = size - 1, middle;

	while (left <= right) {

		middle = left + (right - left) / 2;

		if (arr[middle] == m) return true;
		if (arr[middle] < m) {
			if (middle >= size) return false;
			left = middle + 1;
		}
		else {
			if (middle == 0) return false;
			right = middle - 1;
		}
	}
	return false;
}

int main() {
	std::cin >> n >> m;
	for (unsigned i = 0,help; i < n; ++i) {
		std::cin >> help;
		++arr[help - 1];
	}

	for (unsigned i = 0,help; i < 10000; ++i) {
		if (arr[i]) {
			help = ((i + 1) ^ m);
			if (arr[help + 1]) {
				count += (arr[i] * arr[help + 1]);
			}
		}
	}

	std::cout << count/2;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[100001],count=0;

int main() {
	std::cin >> n >> m;

	for (unsigned i = 0,help,help1; i < n; ++i) {
		std::cin >> help;
		help1 = (help^m);

		count +=  arr[help1];
		++arr[help];
	}

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[100001],count=0;

int main() {
	std::cin >> n >> m;

	for (unsigned i = 0,help,help1; i < n; ++i) {
		std::cin >> help;
		help1 = (help^m);

		if(help1<=100000)count +=  arr[help1]

		++arr[help];
	}

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <alg.h>
#include <algorithm>
#include <string>
#include <cassert>
#include <queue>
#include <vector>
#include <utility>
#include <malloc.h>

INT64 n, m, arr[100001], count = 0;

int main() {
	std::cin >> n >> m;

	for (unsigned i = 0, help, help1; i < n; ++i) {
		std::cin >> help;
		help1 = (help^m);

		if (help1 <= 100000)count += arr[help1];

		++arr[help];
	}

	std::cout << count;
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[100001],count=0;

int main() {
	std::cin >> n >> m;
	for (unsigned i = 0,help,help1; i < n; ++i) {
		std::cin >> help;
		++arr[help];
		help1 = (help^m);

		if(help1<=100000)
			count +=  arr[help1];
	}

	/*for (unsigned i = 1,help; i <= 10000; ++i) {
		if (arr[i]) {
			help = (i ^ m);
			if (help>i)
				count += (arr[i] * arr[help]);

		}
	}*/

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[10001],count=0;

int main() {
	std::cin >> n >> m;
	for (unsigned i = 0,help; i < n; ++i) {
		std::cin >> help;
		++arr[help];
	}

	for (unsigned i = 1,help; i <= 10000; ++i) {
		if (arr[i]) {
			help = (i ^ m);
			if (help>i)
			count += (arr[i] * arr[help]);

		}
	}

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[100001],count=0;

int main() {
	std::cin >> n >> m;

	for (unsigned i = 0,help,help1; i < n; ++i) {
		std::cin >> help;
		help1 = (help^m);

		if (help1 <= 100000)count += arr[help1];

		++arr[help];
	}

	std::cout << count;

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
unsigned n, m,arr[10000],count=0;

bool b(unsigned *arr, unsigned size, unsigned m) {

	unsigned left = 0, right = size - 1, middle;

	while (left <= right) {

		middle = left + (right - left) / 2;

		if (arr[middle] == m) return true;
		if (arr[middle] < m) {
			if (middle >= size) return false;
			left = middle + 1;
		}
		else {
			if (middle == 0) return false;
			right = middle - 1;
		}
	}
	return false;
}

int main() {
	std::cin >> n >> m;
	for (unsigned i = 0; i < n; ++i) {
		std::cin >> arr[i];
	}

	std::sort(arr, arr + n);

	for (unsigned i = 0; i < n-1; ++i) {

		if (b(arr + i + 1, (n - i) - 1, (arr[i] ^ m))) {

			++count;

			while (i < n && arr[i] == arr[i + 1]) {
				++count;
				++i;
			}
			continue;
		}

		while (i < n && arr[i] == arr[i + 1]) ++i;
	}

	std::cout << count;

	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
long long a[100005];

int main()
{

    long long n,x;

    long long k = 0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        long long c;
        cin>>c;
        long long ans=c^x;
        k=k+a[ans];
        a[c]++;
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{

    long long n,x;
    long long a[100005];
    long long k = 0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        long long c;
        cin>>c;
        long long ans;
        ans=c^x;
        k=k+a[ans];
        a[c]++;
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,x,t1;
long long a[1000005];

int main()
{
    ios::sync_with_stdio(false);
    long long ct = 0;
    cin >> n >> x;

    for(int i=1;i<=n;i++)
    {
        cin >> t1;
        long long t = t1^x;
        ct += a[t];
        a[t1]++;
    }
    cout << ct <<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    long long k=0;
    long long a[100005],b[100005]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        long long ans;
        ans=a[i]^x;
        k=k+b[ans];
        b[a[i]]++;
    }

    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{

    long long n,x;
    long long a[100005];
    long long k = 0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        long long c;
        cin>>c;
        long long ans=c^x;
        k=k+a[ans];
        a[c]++;
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    long long k=0;
    long long a[100005],b[100005]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        long long ans;
        ans=a[i]^x;
        k=k+a[ans];
        a[a[i]]++;
    }

    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{

    long long n,x;
    long long a[1000005];
    long long k = 0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        long long c,ans;
        cin>>c;
        long long ans=c^x;
        k=k+a[ans];
        a[c]++;
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
ll n,x,t1;
ll a[1000005];

int main()
{
    ios::sync_with_stdio(false);
    ll ct = 0;
    cin >> n >> x;

    for(int i=1;i<=n;i++)
    {
        cin >> t1;
        ll t = t1^x;
        ct += a[t];
        a[t1]++;
    }
    cout << ct <<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,x,c;
long long a[1000005];

int main()
{
    ios::sync_with_stdio(false);
    long long ct = 0;
    cin >> n >> x;

    for(int i=1;i<=n;i++)
    {
        cin >> c;
        long long t = c^x;
        ct += a[t];
        a[c]++;
    }
    cout << ct <<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
using namespace std;
long long a[100005];
int main()
{

    long long n,x;

    long long k = 0;
    cin>>n>>x;
    for(int i=1;i<=n;i++)
    {
        long long c;
        cin>>c;
        long long ans=c^x;
        k=k+a[ans];
        a[c]++;
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int k=0;
    long long a[100005],b[100005]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        long long ans;
        ans=a[i]^x;
        k=k+b[ans];
        b[a[i]]++;
    }

    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,x,c;
long long a[1000005];

int main()
{
    long long k = 0;
    cin >> n >> x;

    for(int i=1;i<=n;i++)
    {
        cin >> c;
        long long t = c^x;
        k += a[t];
        a[c]++;
    }
    cout << k <<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

const int N=100*1000+10;
int n;
int x;
int b;
int a[N];
int countt;

int my_binary_search(int xx);

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	sort(a, a+n);
		//for(int i=0; i<n; i++) cout<<a[i]<<" ";
		//cout<<endl;
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		//int *ptr = lower_bound(a, a+n, b);
		//if (*ptr == b) countt++;
		countt+=my_binary_search(b);
	}
	cout<<countt/2<<endl;
	return 0;
}

int my_binary_search(int xx) {
		//cout<<"cherche "<<xx<<endl;
	int r=0;
	int left=0; int right=n-1;
	int center=right;
	while((right-left) > 1 && a[center]!=xx) {
			//cout<<"left = "<<left<<" right = "<<right<<" center = "<<center<<endl;
		center=(right+left)/2;
		if(a[center]>xx) right=center;
		else left=center;

	}
	if(a[left]==xx) center=left;
	if(a[right]==xx) center=right;
		//cout<<"center= "<<center<<endl;
	if(a[center]==xx) {
			//cout<<"a[center] "<<a[ce
		r++;
			//cout<<xx<<" ";
		for(int i=center-1; i>=0 && a[i]==xx; i--, r++) {
			//cout<<"i= "<<i<<" ";
			//cout<<"l"<<xx<<" "<<endl;
		}
		for(int i=center+1; i<n && a[i]==xx; i++, r++);// cout<<"r "<<xx<<" ";
			//cout<<endl;
	}
	return r;
}
/*
int *ptr1 = lower_bound(prime, prime+k, t);
					if (*ptr1 == t) {
						int index = ptr1 - prime;
						r[index]++;
						//cout<<"+ chislo, kratnoe "<<t<<endl;
					}
					*/


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;
typedef long long lint;

const int N=100*1000+10;
lint n;
lint x;
lint b;
lint a[N];
lint num_x[N];
lint countt;

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		num_x[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		countt+=num_x[b];
	}
	cout<<countt/2<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;
typedef long long lint;

const int N=100*1000+10;
int n;
int x;
lint b;
int a[N];
int num_x[N];
int countt;

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		num_x[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		countt+=num_x[b];
	}
	cout<<countt/2<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;
typedef long long lint;

const int N=200*1000+10;
lint n;
lint x;
lint b;
lint a[N];
lint num_x[N];
lint countt;

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		num_x[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		countt+=num_x[b];
	}
	cout<<countt/2<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;
typedef long long lint;

const int N=200*1000+10;
lint n;
lint x;
lint b;
lint a[N];
lint num_x[N];
lint countt;

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		num_x[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		countt+=num_x[b];
		if(x==0) countt--;
	}
	cout<<countt/2<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

const int N=100*1000+10;
int n;
int x;
int b;
int a[N];
int num_x[N];
int countt;

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		num_x[a[i]]++;
	}
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		countt+=num_x[b];
	}
	cout<<countt/2<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

const int N=100*1000+10;
int n;
int x;
int b;
int a[N];
int countt;

int my_binary_search(int xx);

int main() {
	cin>>n>>x;
	for(int i=0; i<n; i++) {
		cin>>a[i];
	}
	sort(a, a+n);
		//for(int i=0; i<n; i++) cout<<a[i]<<" ";
		//cout<<endl;
	for(int i=0; i<n; i++) {
		b=a[i]^x;
		//int *ptr = lower_bound(a, a+n, b);
		//if (*ptr == b) countt++;
		countt+=my_binary_search(b);
	}
	cout<<countt/2<<endl;
	return 0;
}

int my_binary_search(int xx) {
		//cout<<"cherche "<<xx<<endl;
	int r=0;
	int left=0; int right=n-1;
	int center=right;
	while((right-left) > 1 && a[center]!=xx) {
			//cout<<"left = "<<left<<" right = "<<right<<" center = "<<center<<endl;
		center=(right+left)/2;
		if(a[center]>xx) right=center;
		else left=center;

	}
	if(a[left]==xx) center=left;
	if(a[right]==xx) center=right;
		//cout<<"center= "<<center<<endl;
	if(a[center]==xx) {
			//cout<<"a[center] "<<a[ce
		r++;
			//cout<<xx<<" ";
		for(int i=center-1; i>=0 && a[i]==xx; i--, r++) {
			//cout<<"i= "<<i<<" ";
			//cout<<"l"<<xx<<" "<<endl;
		}
		for(int i=center+1; i<n && a[i]==xx; i++, r++) cout<<"r "<<xx<<" ";
			//cout<<endl;
	}
	return r;
}


#include <iostream>
using namespace std;
int main()
{
	int n, x;
	cin >> n >> x;
	int a[100000];
	int i, j, q = 0;
	cin >> a[0];
	for (i = 1; i < n; i++)
	{
		cin >> a[i];
		for (j = 0; j < i; j++)
		{
			if ((a[i] ^ a[j]) == x)
				q++;
		}
	}
	cout << q;
}


#include <iostream>
using namespace std;
int main()
{
    long n,res,k,a[1000000];
    long long ans=0;
    cin>>n>>res;
    for(;n>0;n--)
    {
        cin>>k;
        ans+=a[res^k];
        a[k]++;
    }
    cout<<ans<<endl;
}


#include <iostream>
using namespace std;
int main()
{
	int n, x;
	cin >> n >> x;
	int a[100000];
	int i, j, q = 0;
	for (i = 0; i < n; i++)
		cin >> a[i];
	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if ((a[i] ^ a[j]) == x)
				q++;
		}
	}
	cout << q;
}


#include <iostream>
using namespace std;
int main()
{
    int n,res,k,a[1000000];
    long long ans=0;
    cin>>n>>res;
    for(;n>0;n--)
    {
        cin>>k;
        ans+=a[res^k];
        a[k]++;
    }
    cout<<ans<<endl;
}


#include <iostream>
using namespace std;
int main()
{
	int n, x;
	cin >> n >> x;
	int a[100000];
	int i, j;
	int q = 0;
	cin >> a[0];
	for (i = 1; i < n; i++)
	{
		cin >> a[i];
		for (j = 0; j < i; j++)
		{
			if ((a[i] ^ a[j]) == x)
				q++;
		}
	}
	cout << q;
}