// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	ll n, a, b; cin >> n >> a >> b;
	vll x(n);

	rep(i, n) cin >> x[i];

	rep(i, n){
		ll money = ((x[i]*a)/b);
		ll ans =x[i] - ( floor((money*b)/a) );
		cout << ans <<' ';
	}
	cout << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1;// cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	ll n, a, b; cin >> n >> a >> b;

	rep(i, n){
		ll x; cin >> x;
		ll money = floor((x*a)/b);
		ll ans = x - ( ceil((money*b)/a) );
		cout << ans <<' ';
	}
	cout << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1;// cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	ll n, a, b; cin >> n >> a >> b;
	vll x(n);

	rep(i, n) cin >> x[i];

	rep(i, n){
		ll money = floor((x[i]*a)/b);
		ll ans =x[i] - ( (money*b)/a );
		cout << ans <<' ';
	}
	cout << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1;// cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	ll n, a, b; cin >> n >> a >> b;
	vll x(n);

	rep(i, n) cin >> x[i];

	rep(i, n){
		ll money = floor((x[i]*a)/b);
		ll ans =x[i] - ( floor((money*b)/a) );
		cout << ans <<' ';
	}
	cout << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1;// cin >> T;
        while(T--){
            task();
        }

return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include<set>
#include<fstream>
#include<stack>
using namespace std;
void seif()
{
	std::ios_base::sync_with_stdio(0);
}
vector<long long>vi;
int main()
{
    seif();
    long long n,a ,b;cin>>n>>a>>b;
    for(long i = 0 ;i < n ; i++)
    {
        long long x;cin>>x;
        if(x<0)
            cout<<x<<" ";
        else
        {
        long long xu = x*a/b;
        cout<<x-(xu*b)<<" ";
        }
    }
    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include<set>
#include<fstream>
#include<stack>
using namespace std;
void seif()
{
	std::ios_base::sync_with_stdio(0);
}
vector<long long>vi;
int main()
{
    seif();
    long long n,a ,b;cin>>n>>a>>b;
    for(long i = 0 ;i < n ; i++)
    {
        long long x;cin>>x;
        long long xu = x*a/b;
        cout<<x-(xu*b)<<" ";
    }
    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include<set>
#include<fstream>
#include<stack>
using namespace std;
void seif()
{
	std::ios_base::sync_with_stdio(0);
}
vector<long long>vi;
int main()
{
    seif();
    long long n,a ,b;cin>>n>>a>>b;
    for(long i = 0 ;i < n ; i++)
    {
        long long x;cin>>x;
        long long xu = x%b , xv = a%b;
        xu=(xv*xu)%b;
        cout<<xu<<" ";
    }
    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include <stdio.h>
#include <string.h>
#include<set>
#include<fstream>
#include<stack>
using namespace std;
void seif()
{
	std::ios_base::sync_with_stdio(0);
}
vector<long long>vi;
int main()
{
    seif();
    long long n,a ,b;cin>>n>>a>>b;
    for(long i = 0 ;i < n ; i++)
    {
        long long x;cin>>x;
        long long xu = (x*a)%b;
        cout<<xu/a<<" ";
    }
    return 0;
}


#include <iostream>
#include <climits>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#define fileio freopen("input.txt", "r", stdin),freopen("out.txt", "w", stdout)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define ll long long

using namespace std;

int main() {
    SPEED;
    ll n, a, b;
    cin >> n >> a >> b;
    ll w[n];
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        if (w[i]*a >= b) {
            w[i] = (w[i] % b *a) % b;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << w[i] << " ";
    }
}


#include <iostream>
#include <climits>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#define fileio freopen("input.txt", "r", stdin),freopen("out.txt", "w", stdout)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define ll long long

using namespace std;

int main() {
    SPEED;
    ll n, a, b;
    cin >> n >> a >> b;
    ll w[n];
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        if (w[i]*a >= b) {
            w[i] = (w[i]*a) % b;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << w[i] << " ";
    }
}


#include <iostream>
#include <climits>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#define fileio freopen("input.txt", "r", stdin),freopen("out.txt", "w", stdout)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define ll long long

using namespace std;

int main() {
    SPEED;
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll w[n];
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        if ((ll)w[i] >= (b)/a) {
            w[i] = (w[i] % b *a) % b;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << w[i] << " ";
    }
}


#include <iostream>
#include <climits>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#define fileio freopen("input.txt", "r", stdin),freopen("out.txt", "w", stdout)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define ll long long

using namespace std;

int main() {
    SPEED;
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll w[n];
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        if ((ll)w[i] >= (b +a)/a) {
            w[i] = (w[i] % b *a) % b;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << w[i] << " ";
    }
}


#include <iostream>
#include <climits>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#define fileio freopen("input.txt", "r", stdin),freopen("out.txt", "w", stdout)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define ll long long

using namespace std;

int main() {
    SPEED;
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll w[n];
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        w[i] = (w[i] * a % b) / a;
    }
    for (int i = 0; i < n; ++i) {
        cout << w[i] << " ";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll gcd(ll a, ll b) { return !b ? a : gcd(b , a % b); }
ll lcm(ll x, ll y) { return (x * y / gcd(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
int  n , a , b , m , tokens[1001];
int main(){
    scanf("%d %d %d" , &n , &a , &b);
    m = max(a , b);
    for(int i  = 0 ; i < n ; ++i)   scanf("%d" , &tokens[i]);
    for(int i  = 0 ; i < n ; ++i)   printf("%d " , tokens[i] % m );
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll gcd(ll a, ll b) { return !b ? a : gcd(b , a % b); }
ll lcm(ll x, ll y) { return (x * y / gcd(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
ll  n , a , b , tokens[1001];
int main(){
    scanf("%lld %lld %lld" , &n , &a , &b);
    for(int i  = 0 ; i < n ; ++i)   scanf("%d" , &tokens[i]);
    for(int i  = 0 ; i < n ; ++i)   printf("%lld " ,  tokens[i] % (a * b) );
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll gcd(ll a, ll b) { return !b ? a : gcd(b , a % b); }
ll lcm(ll x, ll y) { return (x * y / gcd(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
int  n , a , b , m , tokens[N];
int main(){
    scanf("%d %d %d" , &n , &a , &b);
    m = max(a , b);
    for(int i  = 0 ; i < n ; ++i)   scanf("%d" , &tokens[i]);
    for(int i  = 0 ; i < n ; ++i)   printf("%d " , tokens[i] % m );
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll gcd(ll a, ll b) { return !b ? a : gcd(b , a % b); }
ll lcm(ll x, ll y) { return (x * y / gcd(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
ll  n , a , b , x;
int main(){
    scanf("%lld %lld %lld" , &n , &a , &b);
    for(int i  = 0 ; i < n ; ++i){
        scanf("%lld" , &x);
        ll l = 0 , h = x , val = a * h / b , ans = 0;
            while(l <= h){
                ll mid = (l + h) >> 1;
                if(mid * a / b == val)  h = mid - 1 , ans = mid ;
                else                    l = mid + 1;
              }
        printf("%lld " , x - ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(v, d)		memset(v, d, sizeof(v))
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define Abdulrahman ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e6+5 ,  M = (1 << 16) , MAX = 10  , OO = 0x3f3f3f3f , mod = 1e9+7 ;
ll gcd(ll a, ll b) { return !b ? a : gcd(b , a % b); }
ll lcm(ll x, ll y) { return (x * y / gcd(x, y)); }
ll fact(ll z)      { return (z <= 1) ? 1 : z * fact(z - 1); }
int dx[] = {0 , 0  , 1 , -1 , 1 , -1 ,  1 , -1};
int dy[] = {1 , -1 , 0 , 0 ,  1 , -1 , -1 ,  1};
bool valid(int i , int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
ll  n , a , b , x;
int main(){
    scanf("%lld %lld %lld" , &n , &a , &b);
    for(int i  = 0 ; i < n ; ++i){
        scanf("%lld" , &x);
        printf("%d " ,( (x * a) % b ) / a);
    }
    return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    while(n--)
    {
        ll x,max_money;
       scanf("%I64d", &x);
        max_money=(ll)(x*a)/(ll)b;
        ll coin = x-(max_money*b)/ll(a);
        cout<<coin<<" ";
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

ll res[100005];

int main () {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);

        for (int i = 1; i <= n; ++i) {
                ll ans, t;
                scanf("%I64d", &ans);
                t = ((ll)ans * a) / (ll)b;
                res[i] = ans - (t * b) / (ll)a;
                if((t * b) % (ll)a) res[i]--;
        }

        printf("%I64d", res[1]);
        for (int i = 2; i <= n; ++i)
                printf(" %I64d", res[i]);
        printf("\n");

        return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

ll res[100005];

int main () {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);

        for (int i = 1; i <= n; ++i) {
                ll ans, t;
                scanf("%I64d", &ans);
                t = ((ll)ans * a) / (ll)b;
                res[i] = ans - (t * b) / (ll)a;
               // if((t * b) % (ll)a) res[i]--;
        }

        printf("%I64d", res[1]);
        for (int i = 2; i <= n; ++i)
                printf(" %I64d", res[i]);
        printf("\n");

        return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    while(n--)
    {
        long long int x,max_money;
        cin>>x;
        max_money=(x*a)/b;
        int coin = x-(max_money*(b/a));
        cout<<coin<<" ";
    }
    return 0;
}


// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░Nithish░░░
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.141593
/*
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

void printpri(vll &arr){

		vector<bool>prime(10000001,true);
		int k=0;
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=10000000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=10000000;i++)
		if(prime[i]){
			//cout<<i<<"\n";
			arr[k++]=i;
		}
}
 ll com[101][101];
void combination(){
    memset(com,0,sizeof(com));
     com[1][1] = 1;
	com[1][0] = 1;

	for (int i = 2; i <= 100; i++) {
		com[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			com[i][j] = com[i - 1][j] + com[i - 1][j - 1];
		}
	}
 }

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

ll fxp(ll a, ll b,ll MOD){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2,MOD);
        return (c*c)%MOD;
    }else{
        return (a%MOD *fxp(a,b-1,MOD))%MOD;
    }
}
*/
ll d,v,i,t,j,n,m,m1,r=0,count1=0,q=0,z,p,l,a,b,x,c,k,y;

void solve(){
   cin>>n>>a>>b;
   ll den=double(b)/double(a),f;
   for(int i=0;i<n;i++){
       cin>>f;

       double ans=f%den;
       cout<<ans<<" ";
   }
   cout<<endl;
}
int  main(){

	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  t=1;
  //cin>>t;
  while(t--){
  		solve();
  			}
  	return 0;
}


// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░Nithish░░░
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.141593
/*
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

void printpri(vll &arr){

		vector<bool>prime(10000001,true);
		int k=0;
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=10000000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=10000000;i++)
		if(prime[i]){
			//cout<<i<<"\n";
			arr[k++]=i;
		}
}
 ll com[101][101];
void combination(){
    memset(com,0,sizeof(com));
     com[1][1] = 1;
	com[1][0] = 1;

	for (int i = 2; i <= 100; i++) {
		com[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			com[i][j] = com[i - 1][j] + com[i - 1][j - 1];
		}
	}
 }

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

ll fxp(ll a, ll b,ll MOD){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2,MOD);
        return (c*c)%MOD;
    }else{
        return (a%MOD *fxp(a,b-1,MOD))%MOD;
    }
}
*/
ll d,v,i,t,j,n,m,m1,r=0,count1=0,q=0,z,p,l,a,b,x,c,k,y;

void solve(){
   cin>>n>>a>>b;
   //double den=double(b)/double(a),f;
   for(int i=0;i<n;i++){
      ll w;
       cin>>w;

      ll mod=(w*a)%b;
      ll k1=mod/a;
   cout<<k1<<" ";

   }
   cout<<endl;
}
int  main(){

	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  t=1;
  //cin>>t;
  while(t--){
  		solve();
  			}
  	return 0;
}


#include<bits/stdc++.h>

#define sz(a) ((int)(a).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < n; ++i)
#define forf(i,n) for(int i = 1; i <= n; ++i)
#define forr(i,n) for(int i = n - 1; i >= 0; ++i)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<pair<ll,ll>> vp;
typedef vector<pair<pair<ll,ll>,int>> vpi;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    rep(i,n){
        int x; cin >> x;
        ll l = 0, r = x, val = (x * 1ll * a / b * 1ll), ans = x;
        while(l <= r){
            ll m = l + (r - l) / 2;
            ll tval = (m * 1ll * a / b * 1ll);
            if(tval < val) l = m + 1;
            else{
                ans = m;
                r = m - 1;
            }
        }
        cout << x - ans << ' ';
    }

    return 0;
}


// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░Nithish░░░
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.141593
/*
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

void printpri(vll &arr){

		vector<bool>prime(10000001,true);
		int k=0;
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=10000000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=10000000;i++)
		if(prime[i]){
			//cout<<i<<"\n";
			arr[k++]=i;
		}
}
 ll com[101][101];
void combination(){
    memset(com,0,sizeof(com));
     com[1][1] = 1;
	com[1][0] = 1;

	for (int i = 2; i <= 100; i++) {
		com[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			com[i][j] = com[i - 1][j] + com[i - 1][j - 1];
		}
	}
 }

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

ll fxp(ll a, ll b,ll MOD){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2,MOD);
        return (c*c)%MOD;
    }else{
        return (a%MOD *fxp(a,b-1,MOD))%MOD;
    }
}
*/
ll d,v,i,t,j,n,m,m1,r=0,count1=0,q=0,z,p,l,a,b,x,c,k,y;

void solve(){
   cin>>n>>a>>b;
   double den=double(b)/double(a),f;
   for(int i=0;i<n;i++){
       cin>>f;

      ll mod=(f*a)%b;
      ll k1=mod/a;
   cout<<k1<<" ";

   }
   cout<<endl;
}
int  main(){

	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  t=1;
  //cin>>t;
  while(t--){
  		solve();
  			}
  	return 0;
}


// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░Nithish░░░
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.141593
/*
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

void printpri(vll &arr){

		vector<bool>prime(10000001,true);
		int k=0;
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=10000000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=10000000;i++)
		if(prime[i]){
			//cout<<i<<"\n";
			arr[k++]=i;
		}
}
 ll com[101][101];
void combination(){
    memset(com,0,sizeof(com));
     com[1][1] = 1;
	com[1][0] = 1;

	for (int i = 2; i <= 100; i++) {
		com[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			com[i][j] = com[i - 1][j] + com[i - 1][j - 1];
		}
	}
 }

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

ll fxp(ll a, ll b,ll MOD){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2,MOD);
        return (c*c)%MOD;
    }else{
        return (a%MOD *fxp(a,b-1,MOD))%MOD;
    }
}
*/
ll d,v,i,t,j,n,m,m1,r=0,count1=0,q=0,z,p,l,a,b,x,c,k,y;

void solve(){
   cin>>n>>a>>b;
   double den=double(b)/double(a),f;
   for(int i=0;i<n;i++){
       cin>>f;

       ll ans=f/den;
       ll ans1=ans*den;
       if(a==1|| a==b)
       cout<<f-ceil(ans1)<<" ";

        else
          cout<<f-ceil(ans1)-1<<" ";
   }
   cout<<endl;
}
int  main(){

	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  t=1;
  //cin>>t;
  while(t--){
  		solve();
  			}
  	return 0;
}


// ░█████╗░░░░░░░░░░░░░░░
// ██╔══██╗░░██╗░░░░██╗░░
// ██║░░╚═╝██████╗██████╗
// ██║░░██╗╚═██╔═╝╚═██╔═╝
// ╚█████╔╝░░╚═╝░░░░╚═╝░░
// ░╚════╝░░░░░Nithish░░░
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.141593
/*
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

void printpri(vll &arr){

		vector<bool>prime(10000001,true);
		int k=0;
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=10000000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=10000000;i++)
		if(prime[i]){
			//cout<<i<<"\n";
			arr[k++]=i;
		}
}
 ll com[101][101];
void combination(){
    memset(com,0,sizeof(com));
     com[1][1] = 1;
	com[1][0] = 1;

	for (int i = 2; i <= 100; i++) {
		com[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			com[i][j] = com[i - 1][j] + com[i - 1][j - 1];
		}
	}
 }

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

ll fxp(ll a, ll b,ll MOD){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2,MOD);
        return (c*c)%MOD;
    }else{
        return (a%MOD *fxp(a,b-1,MOD))%MOD;
    }
}
*/
ll d,v,i,t,j,n,m,m1,r=0,count1=0,q=0,z,p,l,a,b,x,c,k,y;

void solve(){
   cin>>n>>a>>b;
   double den=double(b)/double(a),f;
   for(int i=0;i<n;i++){
       cin>>f;

       ll ans=f/den;
       ll ans1=ans*den;
       if(a==1)
       cout<<f-ceil(ans1)<<" ";

        else
          cout<<f-ceil(ans1)-1<<" ";
   }
   cout<<endl;
}
int  main(){

	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  t=1;
  //cin>>t;
  while(t--){
  		solve();
  			}
  	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int t=__gcd(a,b);
	b/=t;
	for(int i=1;i<=n;i++){
		int w;
		scanf("%d",&w);
		w%=b;
		printf("%d ",w);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		INT w;
		scanf("%I64d",&w);
		INT pp=w*a/b;
		printf("%d",(int)(w*a-pp*b)/a);
		if(i<n) cout<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int, int> pii;
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		int w;
		scanf("%d",&w);
		INT pp=w*a/b;
		printf("%d",w-pp*b/a);
		if(i<n) cout<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int, int> pii;
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int t=__gcd(a,b);
	b/=t;a/=t;
	for(int i=1;i<=n;i++){
		int w;
		scanf("%d",&w);
		INT pp=w*a/b;
		printf("%d ",w-pp*b/a);
	}
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int, int> pii;
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int t=__gcd(a,b);
	b/=t;
	for(int i=1;i<=n;i++){
		int w;
		scanf("%d",&w);
		INT pp=w*a/b;
		printf("%d ",w-pp*b/a);
	}
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////

int n;
vector<vector<int>> comb;
vector<int> arr;
void fun(vector<int> v , int pos = 0)
{
	if (v.size() > 1)
		comb.push_back(v);

	if (pos == n)
		return;

	for (int i = pos; i < n; i++)
	{
		v.push_back(arr[i]);
		fun(v, i + 1 );
		v.pop_back();
	}
}

int main()
{
	FIO;
	PIT(2);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		ll res = x * a / b;
		cout << x - (res * b / a) << " ";
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////

int n;
vector<vector<int>> comb;
vector<int> arr;
void fun(vector<int> v , int pos = 0)
{
	if (v.size() > 1)
		comb.push_back(v);

	if (pos == n)
		return;

	for (int i = pos; i < n; i++)
	{
		v.push_back(arr[i]);
		fun(v, i + 1 );
		v.pop_back();
	}
}

int main()
{
	FIO;
	PIT(2);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		ll res = x * a / b;
		cout << (ll)ceil( x - (res * b / a)) << " ";
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////

int n;
vector<vector<int>> comb;
vector<int> arr;
void fun(vector<int> v , int pos = 0)
{
	if (v.size() > 1)
		comb.push_back(v);

	if (pos == n)
		return;

	for (int i = pos; i < n; i++)
	{
		v.push_back(arr[i]);
		fun(v, i + 1 );
		v.pop_back();
	}
}

int main()
{
	FIO;
	PIT(2);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		ll res = x * a / b;
		cout << ceil( x - (res * b / a)) << " ";
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////

int n;
vector<vector<int>> comb;
vector<int> arr;
void fun(vector<int> v , int pos = 0)
{
	if (v.size() > 1)
		comb.push_back(v);

	if (pos == n)
		return;

	for (int i = pos; i < n; i++)
	{
		v.push_back(arr[i]);
		fun(v, i + 1 );
		v.pop_back();
	}
}

int main()
{
	FIO;
	PIT(2);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;

	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		ll res =(( x * a )% b)/a;
		cout << res << " ";
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp, tmp2, chk, chk2, ans;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		tmp2 = tmp * a;
		tmp2 /= b;
		tmp2 *= b;
		tmp2 /= a;
		ans = tmp - tmp2;
	    chk = (tmp2 * a) / b;
	    chk2 = (tmp * a) / b;
	    if(chk != chk2)
	        ans--, tmp2++;
		printf("%lld ", ans);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		long long tmp2 = tmp * a / b;
		tmp -= (long long)(tmp2 * b / a);
		printf("%lld ", tmp);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		long long tmp2 = tmp * a;
		tmp2 /= b;
		tmp2 *= b;
		tmp2 /= a;
		tmp -= tmp2;
		printf("%lld ", tmp);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp, tmp2, chk, chk2, ans;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		tmp2 = tmp * a;
		tmp2 /= b;
		tmp2 *= b;
		tmp2 /= a;
		ans = tmp - tmp2;
		while(true){
		    chk = (tmp2 * a) / b;
		    chk2 = (tmp * a) / b;
		    if(chk != chk2)
		        ans--, tmp2++;
		    else break;
		}
		printf("%lld ", ans);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		long long tmp2 = tmp * a;
		tmp2 /= b;
		tmp2 *= b;
		tmp2 = tmp2 % a + tmp2 / a;
		tmp -= tmp2;
		printf("%lld ", tmp);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		long long tmp2 = tmp * a / b;
		tmp -= (tmp2 * b / a);
		printf("%lld ", tmp);
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	long long a, b, tmp;
	scanf("%lld %lld", &a, &b);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &tmp);
		long long tmp2 = tmp * a;
		tmp2 /= b;
		tmp2 *= b;
		tmp2 = (tmp2 % a != 0) + tmp2 / a;
		tmp -= tmp2;
		printf("%lld ", tmp);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
	fastIO

	ll n,a,b,x;
	cin>>n>>a>>b;
	vector<ll> v;
	for(ll i=0;i<n;i++)
	 {
	 	cin>>x;
		v.pb(x);
	 }
	b=b/(__gcd(a,b));
	for(ll i=0;i<n;i++)
	{
	  v[i]=v[i]%b;
	  cout<<v[i]<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
	fastIO

	ll n,a,b,x;
	cin>>n>>a>>b;
	vector<ll> v;
	for(ll i=0;i<n;i++)
	 {
	 	cin>>x;
		v.pb(x);
	 }
	for(ll i=0;i<n;i++)
	{
		ll d=(v[i]*a)/b;
		ll w=(d*b+a-1)/a;
		if(v[i]-w>=0)
		 cout<<v[i]-w<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
	fastIO

	ll n,a,b,x;
	cin>>n>>a>>b;
	vector<ll> v;
	for(ll i=0;i<n;i++)
	 {
	 	cin>>x;
		v.pb(x);
	 }
	for(ll i=0;i<n;i++)
	{
		ll d=(v[i]*a)/b;
		ll w=(d*b)/a;
		if(v[i]-w>=0)
		 cout<<v[i]-w<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcdn(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcdn(b, a % b);
}
int main()
{
	fastIO

	ll n,a,b,x;
	cin>>n>>a>>b;
	vector<ll> v;
	for(ll i=0;i<n;i++)
	 {
	 	cin>>x;
		v.pb(x);
	 }
	b=b/(gcdn(a,b));
	for(ll i=0;i<n;i++)
	{
	  v[i]=v[i]%b;
	  cout<<v[i]<<" ";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long l;
double v[1000001];
ll s[1000001];

int main(){

    ll w,a,b;
    cin>>w>>a>>b;

    for(ll i=0;i<w;i++) cin>>v[i];

    for(ll i=0;i<w;i++){
    ll temp = floor((v[i]*a)/(double)b);
    ll tokens = ceil((temp*b)/(double)a);

    s[i] = v[i] - tokens;
    }

    for(ll i=0;i<w;i++) cout<<s[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        ll w;
        cin>>w;
        ll res = floor((w*a)/b);
        v.push_back(w-(b*res));
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        ll w;
        cin>>w;
        ll res = ((w*a)/b);
        v.push_back(w-(b*res));
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        ll w;
        cin>>w;
        ll res = (ll)floor((w*a)/b);
        v.push_back(w-(b*res));
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long l;
double v[1000001],s[1000001];

int main(){

    ll w,a,b;
    cin>>w>>a>>b;

    for(ll i=0;i<w;i++) cin>>v[i];

    for(ll i=0;i<w;i++){
    ll temp = floor((v[i]*a)/(double)b);
    ll tokens = ceil((temp*b)/(double)a);

    s[i] = v[i] - tokens;
    }

    for(ll i=0;i<w;i++) cout<<s[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        ll w;
        cin>>w;
        ll res = (w*a/b);
        v.push_back(w-(b*res));
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        float w;
        cin>>w;
        float res = floor(w*(a/(float)b));
        v.push_back(w-(b*res));
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    ll n,a,b;
    cin>>n>>a>>b;
    vector<ll>v;
    for(ll i=0;i<n;i++){
        float w;
        cin>>w;
        float res = floor(w*(a/(float)b));
        float temp = ceil(res*b/(float)a);
        v.push_back(w-temp);
    }

    for(ll i=0;i<n;i++) cout<<v[i]<<" ";

    return 0;

}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define sc second
#define ft first
#define p_q priority_queue
#define INF 10000000000
using namespace std;
const ll MOD=1e9+7;
const ll N=2e5+7;
ll n ,x,m,a,b;
vi ans;
ll res(ll n,ll a,ll b){
    ll tmp=(x*a)/b,res;
    for(ll i=n;i<=x;i++) if((i*a)/b==tmp){ res=i;break; }
    return res;
}
int main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
     cin >> n >> a >> b;
     for(int i=0;i<n;i++){
         cin >> x;
         ll y=(x*a)/b; y=(y*b)/a;
         ans.pb(x-res(y,a,b));
     }
     for(int i=0;i<n;i++) cout << ans[i] <<' '; cout <<'\n';
     return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define sc second
#define ft first
#define p_q priority_queue
#define INF 10000000000
using namespace std;
const ll MOD=1e9+7;
const ll N=2e5+7;
ll n ,x,m,a,b;
vi ans;
ll BS(ll n,ll a,ll b){
    ll st=0,ed=1e18,mid;
    while(st<ed){
        mid=(st+ed)/2;
        if(mid*b>n*a) ed=mid;
        else st=mid+1;
    }
    if(mid*b>n*a) mid--;
    return (mid*b);
}
int main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
     cin >> n >> a >> b;
     for(int i=0;i<n;i++){
         cin >> x;
         if(x*a<b) ans.pb(x*a);
         else {
             ll tmp=BS(x,a,b);
             ans.pb(x-tmp);
         }
     }
     for(int i=0;i<n;i++) cout << ans[i] <<' '; cout <<'\n';
     return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define sc second
#define ft first
#define p_q priority_queue
#define INF 10000000000
using namespace std;
const ll MOD=1e9+7;
const ll N=2e5+7;
ll n ,x,m,a,b;
vi ans;
ll BS(ll n,ll a,ll b){
    ll st=0,ed=1e9,mid;
    while(st<ed){
        mid=(st+ed)/2;
        if(mid*b>n*a) ed=mid;
        else st=mid+1;
    }
    if(mid*b>n*a) mid--;
    return (mid*b);
}
int main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
     cin >> n >> a >> b;
     for(int i=0;i<n;i++){
         cin >> x;
         if(x*a<b) ans.pb(x*a);
         else {
             ll tmp=BS(x,a,b);
             ans.pb(x-tmp);
         }
     }
     for(int i=0;i<n;i++) cout << ans[i] <<' '; cout <<'\n';
     return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define QWQ cout<<"QwQ"<<endl;
#define ll long long
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define F f[i-1][j]
using namespace std;
const int N=101010;
const int qwq=303030;
const int inf=0x3f3f3f3f;
const int p=1000000007;

int n,m,d;
int a[53];
char s[N],z1[53],z2[53];
int ch[N][10],ed[N],fa[N],cnt,now;
ll f[53][25678][2];
vector <int> e[N];
queue <int> q;

inline int read() {
	int sum = 0, f = 1; char c = getchar();
	while(c<'0' || c>'9') { if(c=='-') f = -1; c = getchar(); }
	while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
	return sum * f;
}

void DFS(int u,bool flag) {
	if(ed[u]) flag = 1;
	if(flag) ed[u] = 1;
	for(int i=0;i<e[u].size();i++) DFS(e[u][i],flag);
}

void AC() {
	n = strlen(s+1);
	for(int i=1;i+d/2-1<=n;i++) {
		now = 0;
		for(int j=i;j<=i+d/2-1;j++) {
			int c = s[j] - '0';
			if(!ch[now][c]) ch[now][c] = ++cnt;
			now = ch[now][c];
		}
		ed[now] = 1;
	}
	for(int i=0;i<10;i++) if(ch[0][i]) q.push(ch[0][i]);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i=0;i<10;i++) {
			int v = ch[u][i];
			if(v) {
				fa[v] = ch[ fa[u] ][i];
				q.push(v);
			}
			else ch[u][i] = ch[ fa[u] ][i];
		}
	}
	for(int i=1;i<=cnt;i++) e[ fa[i] ].push_back(i);
	DFS(0,0);
}

int query() {
	ll ans = 0;
	memset(f,0,sizeof(f));
	f[0][0][1] = 1;
	for(int i=1;i<=d;i++) {
		for(int j=0;j<=cnt;j++) {
			for(int k=0;k<10;k++) {
				int v = ch[j][k]; if(ed[v]) continue;
				if(k<a[i]) (f[i][v][0] += F[0] + F[1]) %= p;
				if(k>a[i]) (f[i][v][0] += F[0]) %= p;
				if(k==a[i]) {
					(f[i][v][0] += F[0]) %= p;
					(f[i][v][1] += F[1]) %= p;
				}
			}
		}
	}
	for(int i=0;i<=cnt;i++) (ans += f[d][i][1] + f[d][i][0]) %= p;
	return ans;
}

int main() {
	scanf("%s",s+1);
	scanf("%s%s",z1+1,z2+1); d = strlen(z1+1);
	AC();
	ll shu1 = 0, shu2 = 0;
	for(int i=1;i<=d;i++) a[i] = z1[i] - '0', shu1 = (shu1 * 10 + a[i]) %p;
	int h = d; while(a[h]==0) a[h] = 9, h--; a[h]--; shu1--;
	ll ans1 = query();
	for(int i=1;i<=d;i++) a[i] = z2[i] - '0', shu2 = (shu2 * 10 + a[i]) %p;
	ll ans2 = query();
	cout<<( (shu2-shu1-(ans2-ans1)) %p+p) %p;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define QWQ cout<<"QwQ"<<endl;
#define ll long long
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define F f[i-1][j]
using namespace std;
const int N=101010;
const int qwq=303030;
const int inf=0x3f3f3f3f;
const int p=1000000007;

int n,m,d;
int a[53];
char s[N];
int ch[N][10],ed[N],fa[N],cnt,now;
ll f[53][25678][2][2];
vector <int> e[N];
queue <int> q;

inline int read() {
	int sum = 0, f = 1; char c = getchar();
	while(c<'0' || c>'9') { if(c=='-') f = -1; c = getchar(); }
	while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
	return sum * f;
}

void DFS(int u,bool flag) {
	if(ed[u]) flag = 1;
	if(flag) ed[u] = 1;
	for(int i=0;i<e[u].size();i++) DFS(e[u][i],flag);
}

void AC() {
	n = strlen(s+1);
	for(int i=1;i+d/2-1<=n;i++) {
		now = 0;
		for(int j=i;j<=i+d/2-1;j++) {
			int c = s[j] - '0';
			if(!ch[now][c]) ch[now][c] = ++cnt;
			now = ch[now][c];
		}
		ed[now] = 1;
	}
	for(int i=0;i<10;i++) if(ch[0][i]) q.push(ch[0][i]);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i=0;i<10;i++) {
			int v = ch[u][i];
			if(v) {
				fa[v] = ch[ fa[u] ][i];
				q.push(v);
			}
			else ch[u][i] = ch[ fa[u] ][i];
		}
	}
	// for(int i=0;i<=cnt;i++) {
	// 	cout<<i<<" : ed = "<<ed[i]<<"  ";
	// 	for(int j=0;j<10;j++) cout<<ch[i][j]<<" "; cout<<"\n";
	// }
	for(int i=1;i<=cnt;i++) e[ fa[i] ].push_back(i);
	DFS(0,0);
}

int query(int u) {
	// cout<<u<<" : ";
	int h = 0;
	ll ans = 0;
	memset(f,0,sizeof(f));
	memset(a,0,sizeof(a));
	while(u) { a[d-h] = u%10; u /= 10; h++; }
	f[0][0][1][0] = 1;
	for(int i=1;i<=d;i++) {
		for(int j=0;j<=cnt;j++) {
			for(int k=0;k<10;k++) {
				int v = ch[j][k];
				if(k<a[i]) {
					if(ed[v]) {
						(f[i][v][0][1] += F[1][1] + F[0][1] + F[1][0] + F[0][0]) %= p;
					}
					else {
						(f[i][v][0][1] += F[1][1] + F[0][1]) %= p;
						(f[i][v][0][0] += F[1][0] + F[0][0]) %= p;
					}
				}
				if(k==a[i]) {
					if(ed[v]) {
						(f[i][v][1][1] += F[1][1] + F[1][0]) %= p;
						(f[i][v][0][1] += F[0][1] + F[0][0]) %= p;
					}
					else {
						(f[i][v][1][1] += F[1][1]) %= p;
						(f[i][v][1][0] += F[1][0]) %= p;
						(f[i][v][0][1] += F[0][1]) %= p;
						(f[i][v][0][0] += F[0][0]) %= p;
					}
				}
				if(k>a[i]) {
					if(ed[v]) {
						(f[i][v][0][1] += F[0][1] + F[0][0]) %= p;
					}
					else {
						(f[i][v][0][1] += F[0][1]) %= p;
						(f[i][v][0][0] += F[0][0]) %= p;
					}
				}
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<0<<"] = "<<f[i][v][0][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<1<<"] = "<<f[i][v][0][1]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<0<<"] = "<<f[i][v][1][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<1<<"] = "<<f[i][v][1][1]<<"\n";
			}
		}
	}
	for(int i=0;i<=cnt;i++) (ans += f[d][i][1][1] + f[d][i][0][1]) %= p;
	// cout<<"ans = "<<ans<<"\n";
	return ans;
}

inline int wei(int x) { int res = 0; while(x) { res++; x /= 10; } return res; }

int main() {
	int X,Y;
	scanf("%s",s+1);
	X = read(); Y = read();
	d = wei(X);
	AC();
	cout<<((query(Y)-query(X-1))%p+p)%p;
	return 0;
}

/*

31415926535
10
29

*/


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define QWQ cout<<"QwQ"<<endl;
#define ll long long
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define F f[i-1][j]
using namespace std;
const int N=101010;
const int qwq=303030;
const int inf=0x3f3f3f3f;
const int p=1000000007;

int n,m,d;
int a[53];
char s[N],z1[53],z2[53];
int ch[N][10],ed[N],fa[N],cnt,now;
ll f[53][25678][2][2];
vector <int> e[N];
queue <int> q;

inline int read() {
	int sum = 0, f = 1; char c = getchar();
	while(c<'0' || c>'9') { if(c=='-') f = -1; c = getchar(); }
	while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
	return sum * f;
}

void DFS(int u,bool flag) {
	if(ed[u]) flag = 1;
	if(flag) ed[u] = 1;
	for(int i=0;i<e[u].size();i++) DFS(e[u][i],flag);
}

void AC() {
	n = strlen(s+1);
	for(int i=1;i+d/2-1<=n;i++) {
		now = 0;
		for(int j=i;j<=i+d/2-1;j++) {
			int c = s[j] - '0';
			if(!ch[now][c]) ch[now][c] = ++cnt;
			now = ch[now][c];
		}
		ed[now] = 1;
	}
	for(int i=0;i<10;i++) if(ch[0][i]) q.push(ch[0][i]);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i=0;i<10;i++) {
			int v = ch[u][i];
			if(v) {
				fa[v] = ch[ fa[u] ][i];
				q.push(v);
			}
			else ch[u][i] = ch[ fa[u] ][i];
		}
	}
	// for(int i=0;i<=cnt;i++) {
	// 	cout<<i<<" : ed = "<<ed[i]<<"  ";
	// 	for(int j=0;j<10;j++) cout<<ch[i][j]<<" "; cout<<"\n";
	// }
	for(int i=1;i<=cnt;i++) e[ fa[i] ].push_back(i);
	DFS(0,0);
}

int query() {
	ll ans = 0;
	memset(f,0,sizeof(f));
	f[0][0][1][0] = 1;
	for(int i=1;i<=d;i++) {
		for(int j=0;j<=cnt;j++) {
			for(int k=0;k<10;k++) {
				int v = ch[j][k];
				if(k<a[i]) {
					if(ed[v]) {
						(f[i][v][0][1] += F[1][1] + F[0][1] + F[1][0] + F[0][0]) %= p;
					}
					else {
						(f[i][v][0][1] += F[1][1] + F[0][1]) %= p;
						(f[i][v][0][0] += F[1][0] + F[0][0]) %= p;
					}
				}
				if(k==a[i]) {
					if(ed[v]) {
						(f[i][v][1][1] += F[1][1] + F[1][0]) %= p;
						(f[i][v][0][1] += F[0][1] + F[0][0]) %= p;
					}
					else {
						(f[i][v][1][1] += F[1][1]) %= p;
						(f[i][v][1][0] += F[1][0]) %= p;
						(f[i][v][0][1] += F[0][1]) %= p;
						(f[i][v][0][0] += F[0][0]) %= p;
					}
				}
				if(k>a[i]) {
					if(ed[v]) {
						(f[i][v][0][1] += F[0][1] + F[0][0]) %= p;
					}
					else {
						(f[i][v][0][1] += F[0][1]) %= p;
						(f[i][v][0][0] += F[0][0]) %= p;
					}
				}
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<0<<"] = "<<f[i][v][0][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<1<<"] = "<<f[i][v][0][1]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<0<<"] = "<<f[i][v][1][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<1<<"] = "<<f[i][v][1][1]<<"\n";
			}
		}
	}
	for(int i=0;i<=cnt;i++) (ans += f[d][i][1][1] + f[d][i][0][1]) %= p;
	// cout<<"ans = "<<ans<<"\n";
	return ans;
}

int main() {
	scanf("%s",s+1);
	scanf("%s%s",z1+1,z2+1); d = strlen(z1+1);
	AC();
	for(int i=1;i<=d;i++) a[i] = z1[i] - '0';
	int h = d; while(a[h]==0) a[h] = 9, h--; a[h]--;
	ll ans1 = query();
	for(int i=1;i<=d;i++) a[i] = z2[i] - '0';
	ll ans2 = query();
	cout<<((ans2-ans1)%p+p)%p;
	return 0;
}

/*

31415926535
10
29

*/


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define QWQ cout<<"QwQ"<<endl;
#define ll long long
#include <vector>
#include <queue>
#include <stack>
#include <map>
#define F f[i-1][j]
using namespace std;
const int N=101010;
const int qwq=303030;
const int inf=0x3f3f3f3f;

int n,m,d;
int a[53];
char s[N];
int ch[N][10],ed[N],fa[N],cnt,now;
int f[53][25678][2][2];
vector <int> e[N];
queue <int> q;

inline int read() {
	int sum = 0, f = 1; char c = getchar();
	while(c<'0' || c>'9') { if(c=='-') f = -1; c = getchar(); }
	while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
	return sum * f;
}

void DFS(int u,bool flag) {
	if(ed[u]) flag = 1;
	if(flag) ed[u] = 1;
	for(int i=0;i<e[u].size();i++) DFS(e[u][i],flag);
}

void AC() {
	n = strlen(s+1);
	for(int i=1;i+d/2-1<=n;i++) {
		now = 0;
		for(int j=i;j<=i+d/2-1;j++) {
			int c = s[j] - '0';
			if(!ch[now][c]) ch[now][c] = ++cnt;
			now = ch[now][c];
		}
		ed[now] = 1;
	}
	for(int i=0;i<10;i++) if(ch[0][i]) q.push(ch[0][i]);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i=0;i<10;i++) {
			int v = ch[u][i];
			if(v) {
				fa[v] = ch[ fa[u] ][i];
				q.push(v);
			}
			else ch[u][i] = ch[ fa[u] ][i];
		}
	}
	// for(int i=0;i<=cnt;i++) {
	// 	cout<<i<<" : ed = "<<ed[i]<<"  ";
	// 	for(int j=0;j<10;j++) cout<<ch[i][j]<<" "; cout<<"\n";
	// }
	for(int i=1;i<=cnt;i++) e[ fa[i] ].push_back(i);
	DFS(0,0);
}

int query(int u) {
	// cout<<u<<" : ";
	int h = 0, ans = 0;
	memset(f,0,sizeof(f));
	memset(a,0,sizeof(a));
	while(u) { a[d-h] = u%10; u /= 10; h++; }
	f[0][0][1][0] = 1;
	for(int i=1;i<=d;i++) {
		for(int j=0;j<=cnt;j++) {
			for(int k=0;k<10;k++) {
				int v = ch[j][k];
				if(k<a[i]) {
					if(ed[v]) {
						f[i][v][0][1] += F[1][1] + F[0][1] + F[1][0] + F[0][0];
					}
					else {
						f[i][v][0][1] += F[1][1] + F[0][1];
						f[i][v][0][0] += F[1][0] + F[0][0];
					}
				}
				if(k==a[i]) {
					if(ed[v]) {
						f[i][v][1][1] += F[1][1] + F[1][0];
						f[i][v][0][1] += F[0][1] + F[0][0];
					}
					else {
						f[i][v][1][1] += F[1][1];
						f[i][v][1][0] += F[1][0];
						f[i][v][0][1] += F[0][1];
						f[i][v][0][0] += F[0][0];
					}
				}
				if(k>a[i]) {
					if(ed[v]) {
						f[i][v][0][1] += F[0][1] + F[0][0];
					}
					else {
						f[i][v][0][1] += F[0][1];
						f[i][v][0][0] += F[0][0];
					}
				}
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<0<<"] = "<<f[i][v][0][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<0<<"]["<<1<<"] = "<<f[i][v][0][1]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<0<<"] = "<<f[i][v][1][0]<<"  ";
				// cout<<"f["<<i<<"]["<<v<<"]["<<1<<"]["<<1<<"] = "<<f[i][v][1][1]<<"\n";
			}
		}
	}
	for(int i=0;i<=cnt;i++) ans += f[d][i][1][1] + f[d][i][0][1];
	// cout<<"ans = "<<ans<<"\n";
	return ans;
}

inline int wei(int x) { int res = 0; while(x) { res++; x /= 10; } return res; }

int main() {
	int X,Y;
	scanf("%s",s+1);
	X = read(); Y = read();
	d = wei(X);
	AC();
	cout<<query(Y)-query(X-1);
	return 0;
}

/*

31415926535
10
29

*/


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <deque>
#include <complex>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pbk pop_back
#define sz(s) ((int) (s).size())
#define len(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL42
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#define cerr if (0) cerr
#endif
#if _WIN32 || __WIN32__ || _WIN64 || __WIN64__
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define next _next
#define prev _prev
#define link _link
#define rank _rank
#define hash _hash

typedef long long ll;
typedef long long llong;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef unsigned long long ullong;
typedef unsigned long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double eps = 1e-9;
const double pi = 4 * atan(1.0);
const int N = 1010;
const int M = 25;
const int MOD = int(1e9) + 7;

int sz;
char s[N], x[N], y[N];
int pv[N * M], pc[N * M], link[N * M], q[N * M], len[N * M];
int next[N * M][10], go[N * M][10];
int dp[N * M][2][2], ndp[N * M][2][2];

inline void build() {
    scanf("%s", s);
    int n = strlen(s);
    sz = 1;
    for (int i = 0; i < 10; ++i) {
        next[0][i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < M && i + j < n; ++j) {
            if (next[cur][s[i + j] - '0'] == -1) {
                for (int z = 0; z < 10; ++z) {
                    next[sz][z] = -1;
                }
                pv[sz] = cur;
                pc[sz] = s[i + j] - '0';
                len[sz] = len[cur] + 1;
                next[cur][s[i + j] - '0'] = sz++;
            }
            cur = next[cur][s[i + j] - '0'];
        }
    }
    int l = 0, r = 1;
    q[0] = 0;
    while (l < r) {
        int v = q[l++];
        if (v == 0 || pv[v] == 0) {
            link[v] = 0;
        } else {
            link[v] = go[link[pv[v]]][pc[v]];
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                go[v][i] = next[v][i];
            } else {
                if (v == 0) {
                    go[v][i] = 0;
                } else {
                    go[v][i] = go[link[v]][i];
                }
            }
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                q[r++] = next[v][i];
            }
        }
    }
}

inline int calc(char* s) {
    int n = strlen(s);
    assert(n / 2 <= M);
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int z = 0; z < 2; ++z) {
                dp[i][j][z] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    ndp[j][z][h] = 0;
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    if (dp[j][z][h] == 0) {
                        continue;
                    }
                    for (int c = (i == 0 ? 1 : 0); c <= (h ? s[i] - '0' : 9); ++c) {
                        int nj = go[j][c];
                        int nz = (z | (len[nj] >= n / 2));
                        int nh = h;
                        if (h && c < s[i] - '0') {
                            nh = 0;
                        }
                        ndp[nj][nz][nh] += dp[j][z][h];
                        if (ndp[nj][nz][nh] >= MOD) {
                            ndp[nj][nz][nh] -= MOD;
                        }
                    }
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    dp[j][z][h] = ndp[j][z][h];
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < sz; ++i) {
        ans = (ans + dp[i][1][0]) % MOD;
        ans = (ans + dp[i][1][1]) % MOD;
    }
    return ans;
}

inline bool check(char* s) {
    int n = strlen(s), cur = 0, max_len = 0;
    for (int i = 0; i < n; ++i) {
        cur = go[cur][s[i] - '0'];
        max_len = max(max_len, len[cur]);
    }
    if (max_len >= n / 2) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cerr << (sizeof(dp) + sizeof(ndp)) / 1024 / 1024 << endl;
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    build();
    scanf("%s %s", x, y);
    int n = strlen(x);
    int ptr = 0;
    while (ptr < n && x[ptr] == y[ptr]) {
        ++ptr;
    }
    if (ptr < n && x[ptr] > y[ptr]) {
        puts("0");
        return 0;
    }
    int ans = (MOD - calc(x)) % MOD;
    if (check(x)) {
        ans = (ans + 1) % MOD;
    }
    ans = (ans + calc(y)) % MOD;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <deque>
#include <complex>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pbk pop_back
#define sz(s) ((int) (s).size())
#define len(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL42
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#define cerr if (0) cerr
#endif
#if _WIN32 || __WIN32__ || _WIN64 || __WIN64__
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define next _next
#define prev _prev
#define link _link
#define rank _rank
#define hash _hash

typedef long long ll;
typedef long long llong;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef unsigned long long ullong;
typedef unsigned long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double eps = 1e-9;
const double pi = 4 * atan(1.0);
const int N = 1010;
const int M = 25;
const int MOD = int(1e9) + 7;

int sz;
char s[N];
int pv[N * M], pc[N * M], link[N * M], q[N * M], len[N * M];
int next[N * M][10], go[N * M][10];
int dp[N * M][M + 1][2], ndp[N * M][M + 1][2];

inline void build() {
    scanf("%s", s);
    int n = strlen(s);
    sz = 1;
    for (int i = 0; i < 10; ++i) {
        next[0][i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < M && i + j < n; ++j) {
            if (next[cur][s[i + j] - '0'] == -1) {
                for (int z = 0; z < 10; ++z) {
                    next[sz][z] = -1;
                }
                pv[sz] = cur;
                pc[sz] = s[i + j] - '0';
                len[sz] = len[cur] + 1;
                next[cur][s[i + j] - '0'] = sz++;
            }
            cur = next[cur][s[i + j] - '0'];
        }
    }
    int l = 0, r = 1;
    q[0] = 0;
    while (l < r) {
        int v = q[l++];
        if (v == 0 || pv[v] == 0) {
            link[v] = 0;
        } else {
            link[v] = go[link[pv[v]]][pc[v]];
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                go[v][i] = next[v][i];
            } else {
                go[v][i] = go[link[v]][i];
            }
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                q[r++] = next[v][i];
            }
        }
    }
}

inline int calc() {
    scanf("%s", s);
    int n = strlen(s);
    assert(n / 2 <= M);
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j <= n / 2; ++j) {
            for (int z = 0; z < 2; ++z) {
                dp[i][j][z] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    ndp[j][z][h] = 0;
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    if (dp[j][z][h] == 0) {
                        continue;
                    }
                    for (int c = (i == 0 ? 1 : 0); c <= (h ? s[i] - '0' : 9); ++c) {
                        int nj = go[j][c];
                        int nz = max(z, len[nj]);
                        if (nz > n / 2) {
                            nz = n / 2;
                        }
                        int nh = h;
                        if (h && c < s[i] - '0') {
                            nh = 0;
                        }
                        ndp[nj][nz][nh] += dp[j][z][h];
                        if (ndp[nj][nz][nh] >= MOD) {
                            ndp[nj][nz][nh] -= MOD;
                        }
                    }
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    dp[j][z][h] = ndp[j][z][h];
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < sz; ++i) {
        ans = (ans + dp[i][n / 2][0]) % MOD;
        ans = (ans + dp[i][n / 2][1]) % MOD;
    }
    return ans;
}

inline bool check() {
    int n = strlen(s), cur = 0, max_len = 0;
    for (int i = 0; i < n; ++i) {
        cur = go[cur][s[i] - '0'];
        max_len = max(max_len, len[cur]);
    }
    if (max_len >= n / 2) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cerr << (sizeof(dp) + sizeof(ndp)) / 1024 / 1024 << endl;
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    build();
    int ans = (MOD - calc()) % MOD;
    if (check()) {
        ans = (ans + 1) % MOD;
    }
    ans = (ans + calc()) % MOD;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <deque>
#include <complex>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pbk pop_back
#define sz(s) ((int) (s).size())
#define len(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL42
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#define cerr if (0) cerr
#endif
#if _WIN32 || __WIN32__ || _WIN64 || __WIN64__
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define next _next
#define prev _prev
#define link _link
#define rank _rank
#define hash _hash

typedef long long ll;
typedef long long llong;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef unsigned long long ullong;
typedef unsigned long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double eps = 1e-9;
const double pi = 4 * atan(1.0);
const int N = 1010;
const int M = 25;
const int MOD = int(1e9) + 7;

int sz;
char s[N], x[N], y[N];
int pv[N * M], pc[N * M], link[N * M], q[N * M], len[N * M];
int next[N * M][10], go[N * M][10];
int dp[N * M][2][2], ndp[N * M][2][2];

inline void build() {
    scanf("%s", s);
    int n = strlen(s);
    sz = 1;
    for (int i = 0; i < 10; ++i) {
        next[0][i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < M && i + j < n; ++j) {
            if (next[cur][s[i + j] - '0'] == -1) {
                for (int z = 0; z < 10; ++z) {
                    next[sz][z] = -1;
                }
                pv[sz] = cur;
                pc[sz] = s[i + j] - '0';
                len[sz] = len[cur] + 1;
                next[cur][s[i + j] - '0'] = sz++;
            }
            cur = next[cur][s[i + j] - '0'];
        }
    }
    int l = 0, r = 1;
    q[0] = 0;
    while (l < r) {
        int v = q[l++];
        if (v == 0 || pv[v] == 0) {
            link[v] = 0;
        } else {
            link[v] = go[link[v]][pc[v]];
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                go[v][i] = next[v][i];
            } else {
                go[v][i] = go[link[v]][i];
            }
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                q[r++] = next[v][i];
            }
        }
    }
}

inline int calc(char* s) {
    int n = strlen(s);
    assert(n / 2 <= M);
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int z = 0; z < 2; ++z) {
                dp[i][j][z] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    ndp[j][z][h] = 0;
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    if (dp[j][z][h] == 0) {
                        continue;
                    }
                    for (int c = (i == 0 ? 1 : 0); c <= (h ? s[i] - '0' : 9); ++c) {
                        int nj = go[j][c];
                        int nz = (z | (len[nj] >= n / 2));
                        int nh = h;
                        if (h && c < s[i] - '0') {
                            nh = 0;
                        }
                        ndp[nj][nz][nh] += dp[j][z][h];
                        if (ndp[nj][nz][nh] >= MOD) {
                            ndp[nj][nz][nh] -= MOD;
                        }
                    }
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    dp[j][z][h] = ndp[j][z][h];
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < sz; ++i) {
        ans = (ans + dp[i][1][0]) % MOD;
        ans = (ans + dp[i][1][1]) % MOD;
    }
    return ans;
}

inline bool check(char* s) {
    int n = strlen(s), cur = 0, max_len = 0;
    for (int i = 0; i < n; ++i) {
        cur = go[cur][s[i] - '0'];
        max_len = max(max_len, len[cur]);
    }
    if (max_len >= n / 2) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cerr << (sizeof(dp) + sizeof(ndp)) / 1024 / 1024 << endl;
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    build();
    scanf("%s %s", x, y);
    int n = strlen(x);
    int ptr = 0;
    while (ptr < n && x[ptr] == y[ptr]) {
        ++ptr;
    }
    if (x[ptr] > y[ptr]) {
        puts("0");
        return 0;
    }
    int ans = (MOD - calc(x)) % MOD;
    if (check(x)) {
        ans = (ans + 1) % MOD;
    }
    ans = (ans + calc(y)) % MOD;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <deque>
#include <complex>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pbk pop_back
#define sz(s) ((int) (s).size())
#define len(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL42
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#define cerr if (0) cerr
#endif
#if _WIN32 || __WIN32__ || _WIN64 || __WIN64__
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define next _next
#define prev _prev
#define link _link
#define rank _rank
#define hash _hash

typedef long long ll;
typedef long long llong;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef unsigned long long ullong;
typedef unsigned long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double eps = 1e-9;
const double pi = 4 * atan(1.0);
const int N = 1010;
const int M = 25;
const int MOD = int(1e9) + 7;

int sz;
char s[N];
int pv[N * M], pc[N * M], link[N * M], q[N * M], len[N * M];
int next[N * M][10], go[N * M][10];
int dp[N * M][M + 1][2], ndp[N * M][M + 1][2];

inline void build() {
    scanf("%s", s);
    int n = strlen(s);
    sz = 1;
    for (int i = 0; i < 10; ++i) {
        next[0][i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < M && i + j < n; ++j) {
            if (next[cur][s[i + j] - '0'] == -1) {
                for (int z = 0; z < 10; ++z) {
                    next[sz][z] = -1;
                }
                pv[sz] = cur;
                pc[sz] = s[i + j] - '0';
                len[sz] = len[cur] + 1;
                next[cur][s[i + j] - '0'] = sz++;
            }
            cur = next[cur][s[i + j] - '0'];
        }
    }
    int l = 0, r = 1;
    q[0] = 0;
    while (l < r) {
        int v = q[l++];
        if (v == 0 || pv[v] == 0) {
            link[v] = 0;
        } else {
            link[v] = go[link[v]][pc[v]];
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                go[v][i] = next[v][i];
            } else {
                go[v][i] = go[link[v]][i];
            }
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                q[r++] = next[v][i];
            }
        }
    }
}

inline int calc() {
    scanf("%s", s);
    int n = strlen(s);
    assert(n / 2 <= M);
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j <= n / 2; ++j) {
            for (int z = 0; z < 2; ++z) {
                dp[i][j][z] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    ndp[j][z][h] = 0;
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    if (dp[j][z][h] == 0) {
                        continue;
                    }
                    for (int c = (i == 0 ? 1 : 0); c <= (h ? s[i] - '0' : 9); ++c) {
                        int nj = go[j][c];
                        int nz = max(z, len[nj]);
                        if (nz > n / 2) {
                            nz = n / 2;
                        }
                        int nh = h;
                        if (h && c < s[i] - '0') {
                            nh = 0;
                        }
                        ndp[nj][nz][nh] += dp[j][z][h];
                        if (ndp[nj][nz][nh] >= MOD) {
                            ndp[nj][nz][nh] -= MOD;
                        }
                    }
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z <= n / 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    dp[j][z][h] = ndp[j][z][h];
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < sz; ++i) {
        ans = (ans + dp[i][n / 2][0]) % MOD;
        ans = (ans + dp[i][n / 2][1]) % MOD;
    }
    return ans;
}

inline bool check() {
    int n = strlen(s), cur = 0, max_len = 0;
    for (int i = 0; i < n; ++i) {
        cur = go[cur][s[i] - '0'];
        max_len = max(max_len, len[cur]);
    }
    if (max_len >= n / 2) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cerr << (sizeof(dp) + sizeof(ndp)) / 1024 / 1024 << endl;
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    build();
    int ans = (MOD - calc()) % MOD;
    if (check()) {
        ans = (ans + 1) % MOD;
    }
    ans = (ans + calc()) % MOD;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <deque>
#include <complex>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pbk pop_back
#define sz(s) ((int) (s).size())
#define len(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL42
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#define cerr if (0) cerr
#endif
#if _WIN32 || __WIN32__ || _WIN64 || __WIN64__
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define next _next
#define prev _prev
#define link _link
#define rank _rank
#define hash _hash

typedef long long ll;
typedef long long llong;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef unsigned long long ullong;
typedef unsigned long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double eps = 1e-9;
const double pi = 4 * atan(1.0);
const int N = 1010;
const int M = 25;
const int MOD = int(1e9) + 7;

int sz;
char s[N], x[N], y[N];
int pv[N * M], pc[N * M], link[N * M], q[N * M], len[N * M];
int next[N * M][10], go[N * M][10];
int dp[N * M][2][2], ndp[N * M][2][2];

inline void build() {
    scanf("%s", s);
    int n = strlen(s);
    sz = 1;
    for (int i = 0; i < 10; ++i) {
        next[0][i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        int cur = 0;
        for (int j = 0; j < M && i + j < n; ++j) {
            if (next[cur][s[i + j] - '0'] == -1) {
                for (int z = 0; z < 10; ++z) {
                    next[sz][z] = -1;
                }
                pv[sz] = cur;
                pc[sz] = s[i + j] - '0';
                len[sz] = len[cur] + 1;
                next[cur][s[i + j] - '0'] = sz++;
            }
            cur = next[cur][s[i + j] - '0'];
        }
    }
    int l = 0, r = 1;
    q[0] = 0;
    while (l < r) {
        int v = q[l++];
        if (v == 0 || pv[v] == 0) {
            link[v] = 0;
        } else {
            link[v] = go[pv[v]][pc[v]];
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                go[v][i] = next[v][i];
            } else {
                if (v == 0) {
                    go[v][i] = 0;
                } else {
                    go[v][i] = go[link[v]][i];
                }
            }
        }
        for (int i = 0; i < 10; ++i) {
            if (next[v][i] != -1) {
                q[r++] = next[v][i];
            }
        }
    }
}

inline int calc(char* s) {
    int n = strlen(s);
    assert(n / 2 <= M);
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int z = 0; z < 2; ++z) {
                dp[i][j][z] = 0;
            }
        }
    }
    dp[0][0][1] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    ndp[j][z][h] = 0;
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    if (dp[j][z][h] == 0) {
                        continue;
                    }
                    for (int c = (i == 0 ? 1 : 0); c <= (h ? s[i] - '0' : 9); ++c) {
                        int nj = go[j][c];
                        int nz = (z | (len[nj] >= n / 2));
                        int nh = h;
                        if (h && c < s[i] - '0') {
                            nh = 0;
                        }
                        ndp[nj][nz][nh] += dp[j][z][h];
                        if (ndp[nj][nz][nh] >= MOD) {
                            ndp[nj][nz][nh] -= MOD;
                        }
                    }
                }
            }
        }
        for (int j = 0; j < sz; ++j) {
            for (int z = 0; z < 2; ++z) {
                for (int h = 0; h < 2; ++h) {
                    dp[j][z][h] = ndp[j][z][h];
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < sz; ++i) {
        ans = (ans + dp[i][1][0]) % MOD;
        ans = (ans + dp[i][1][1]) % MOD;
    }
    return ans;
}

inline bool check(char* s) {
    int n = strlen(s), cur = 0, max_len = 0;
    for (int i = 0; i < n; ++i) {
        cur = go[cur][s[i] - '0'];
        max_len = max(max_len, len[cur]);
    }
    if (max_len >= n / 2) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cerr << (sizeof(dp) + sizeof(ndp)) / 1024 / 1024 << endl;
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    build();
    scanf("%s %s", x, y);
    int n = strlen(x);
    int ptr = 0;
    while (ptr < n && x[ptr] == y[ptr]) {
        ++ptr;
    }
    if (ptr < n && x[ptr] > y[ptr]) {
        puts("0");
        return 0;
    }
    int ans = (MOD - calc(x)) % MOD;
    if (check(x)) {
        ans = (ans + 1) % MOD;
    }
    ans = (ans + calc(y)) % MOD;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N=2e5+5,MOD=1e9+7;

char s[N],x[N],y[N];

int c[N][11],fail[N],mark[N],ss;
void init()
{
    for(int i=0;i<=ss;i++){
        for(int j=0;j<10;j++)c[i][j]=0;
        fail[i]=mark[i]=0;
    }
    ss=0;
}
void add(char *s,int n)
{
    int now=0,t;
    for(int i=1;i<=n;i++){
        t=s[i]-'0';
        if(!c[now][t])c[now][t]=++ss;
        now=c[now][t];
    }
    mark[now]=1;
}
void build()
{
    queue<int>que;
    for(int i=0;i<10;i++)if(c[0][i])fail[c[0][i]]=0,que.push(c[0][i]);
    while(!que.empty()){
        int x=que.front();que.pop();
        mark[x]|=mark[fail[x]];
        for(int i=0;i<10;i++){
            if(c[x][i]){
                fail[c[x][i]]=c[fail[x]][i];
                que.push(c[x][i]);
            }
            else c[x][i]=c[fail[x]][i];
        }
    }
}

int LEN,D;

int f[52][1005*27][2][2];
int dfs(char *s,int x,int y,int lim,int ok)
{
    if(x>D){
        return ok;
    }

    if(f[x][y][lim][ok])return f[x][y][lim][ok];

    int up=lim?s[x]-'0':9;
    int res=0;
    for(int i=0;i<=up;i++){
        int t=c[y][i];
        (res+=dfs(s,x+1,t,lim&&i==up,ok|mark[t]))%=MOD;
    }

    f[x][y][lim][ok]=res;
    return res;
}

int cal(char *s)
{
    for(int i=0;i<=D;i++)
        for(int j=0;j<=ss;j++)
            for(int p1=0;p1<2;p1++)
                for(int p2=0;p2<2;p2++)
                    f[i][j][p1][p2]=0;
    return dfs(s,1,0,1,0);
}

int main()
{
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int cas;
    for(cin>>cas;cas--;){
        cin>>s+1>>x+1>>y+1;

        LEN=strlen(s+1),D=strlen(x+1);
        for(int j=1;j<=LEN;j++){
            if(LEN-j+1>=D/2) add(s+j-1,D/2);
        }
        build();

        int t=D;x[t]--;
        while(x[t]<'0')x[t-1]--,x[t]+=10,t--;

        int res=(cal(y)-cal(x)+MOD)%MOD;
        cout<<res<<'\n';

        init();
    }
    return 0;
}#include <bits/stdc++.h>
using namespace std;

const int N=2e5+5,MOD=1e9+7;

char s[N],x[N],y[N];

int c[N][11],fail[N],mark[N],ss;
void init()
{
    for(int i=0;i<=ss;i++){
        for(int j=0;j<10;j++)c[i][j]=0;
        fail[i]=mark[i]=0;
    }
    ss=0;
}
void add(char *s,int n)
{
    int now=0,t;
    for(int i=1;i<=n;i++){
        t=s[i]-'0';
        if(!c[now][t])c[now][t]=++ss;
        now=c[now][t];
    }
    mark[now]=1;
}
void build()
{
    queue<int>que;
    for(int i=0;i<10;i++)if(c[0][i])fail[c[0][i]]=0,que.push(c[0][i]);
    while(!que.empty()){
        int x=que.front();que.pop();
        mark[x]|=mark[fail[x]];
        for(int i=0;i<10;i++){
            if(c[x][i]){
                fail[c[x][i]]=c[fail[x]][i];
                que.push(c[x][i]);
            }
            else c[x][i]=c[fail[x]][i];
        }
    }
}

int LEN,D;

int f[52][1005*27][2][2];
int dfs(char *s,int x,int y,int lim,int ok)
{
    if(x>D){
        return ok;
    }

    if(f[x][y][lim][ok])return f[x][y][lim][ok];

    int up=lim?s[x]-'0':9;
    int res=0;
    for(int i=0;i<=up;i++){
        int t=c[y][i];
        (res+=dfs(s,x+1,t,lim&&i==up,ok|mark[t]))%=MOD;
    }

    f[x][y][lim][ok]=res;
    return res;
}

int cal(char *s)
{
    for(int i=0;i<=D;i++)
        for(int j=0;j<=ss;j++)
            for(int p1=0;p1<2;p1++)
                for(int p2=0;p2<2;p2++)
                    f[i][j][p1][p2]=0;
    return dfs(s,1,0,1,0);
}

int main()
{
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int cas;
    for(cin>>cas;cas--;){
        cin>>s+1>>x+1>>y+1;

        LEN=strlen(s+1),D=strlen(x+1);
        for(int j=1;j<=LEN;j++){
            if(LEN-j+1>=D/2) add(s+j-1,D/2);
        }
        build();

        int t=D;x[t]--;
        while(x[t]<'0')x[t-1]--,x[t]+=10,t--;

        int res=(cal(y)-cal(x)+MOD)%MOD;
        cout<<res<<'\n';

        init();
    }
    return 0;
}#include <bits/stdc++.h>
using namespace std;

const int N=2e5+5,MOD=1e9+7;

char s[N],x[N],y[N];

int c[N][11],fail[N],mark[N],ss;
void init()
{
    for(int i=0;i<=ss;i++){
        for(int j=0;j<10;j++)c[i][j]=0;
        fail[i]=mark[i]=0;
    }
    ss=0;
}
void add(char *s,int n)
{
    int now=0,t;
    for(int i=1;i<=n;i++){
        t=s[i]-'0';
        if(!c[now][t])c[now][t]=++ss;
        now=c[now][t];
    }
    mark[now]=1;
}
void build()
{
    queue<int>que;
    for(int i=0;i<10;i++)if(c[0][i])fail[c[0][i]]=0,que.push(c[0][i]);
    while(!que.empty()){
        int x=que.front();que.pop();
        mark[x]|=mark[fail[x]];
        for(int i=0;i<10;i++){
            if(c[x][i]){
                fail[c[x][i]]=c[fail[x]][i];
                que.push(c[x][i]);
            }
            else c[x][i]=c[fail[x]][i];
        }
    }
}

int LEN,D;

int f[52][1005*27][2][2];
int dfs(char *s,int x,int y,int lim,int ok)
{
    if(x>D){
        return ok;
    }

    if(f[x][y][lim][ok])return f[x][y][lim][ok];

    int up=lim?s[x]-'0':9;
    int res=0;
    for(int i=0;i<=up;i++){
        int t=c[y][i];
        (res+=dfs(s,x+1,t,lim&&i==up,ok|mark[t]))%=MOD;
    }

    f[x][y][lim][ok]=res;
    return res;
}

int cal(char *s)
{
    for(int i=0;i<=D;i++)
        for(int j=0;j<=ss;j++)
            for(int p1=0;p1<2;p1++)
                for(int p2=0;p2<2;p2++)
                    f[i][j][p1][p2]=0;
    return dfs(s,1,0,1,0);
}

int main()
{
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);

    int cas;
    for(cin>>cas;cas--;){
        cin>>s+1>>x+1>>y+1;

        LEN=strlen(s+1),D=strlen(x+1);
        for(int j=1;j<=LEN;j++){
            if(LEN-j+1>=D/2) add(s+j-1,D/2);
        }
        build();

        int t=D;x[t]--;
        while(x[t]<'0')x[t-1]--,x[t]+=10,t--;

        int res=(cal(y)-cal(x)+MOD)%MOD;
        cout<<res<<'\n';

        init();
    }
    return 0;
}