////#include<iostream>
////#include<vector>
////#include<algorithm>
////#include<cstring>
////using namespace std;
////const int maxn=6005;
////int dp[maxn][2],father[maxn];
////vector<int>G[maxn];
////
////void init()
////{
////	memset(father,-1,sizeof(father));
////}
////
////void dfs(int root)
////{
////	for(int i=0;i<G[root].size();++i)
////	{
////	    dfs(G[root][i]);
////		dp[root][0]+=max(dp[G[root][i]][0],dp[G[root][i]][1]);
////		dp[root][1]+=dp[G[root][i]][0];
////	}
////	return ;
////}
////
////int main()
////{
////	int n,l,k;
////	cin>>n;
////	init();
////	for(int i=1;i<=n;++i)
////	{
////		cin>>dp[i][1];//每个点有两个状态，0和1，分别代表取和不取
////	}
////	while(scanf("%d%d",&l,&k)&&l+k)
////	{
////		//k是l的直接上司
////		father[l]=k;
////		G[k].push_back(l);
////	}
////	//从根节点开始dp，寻找根节点
////	int root=1;
////	while(father[root]!=-1) root=father[root];
////	dfs(root);
////	printf("%d\n",max(dp[root][1],dp[root][0]));
////	return 0;
////}
//#include<algorithm>
//#include<iostream>
//#include<map>
//#include<cstring>
//#include<vector>
//using namespace std;
//typedef long long ll;
//const int maxn=1e6+100;
//ll a[maxn],phi[maxn];
//ll exmod(ll a,ll m)
//{
//    return a>=m?a%m+m:a;
//}
//ll exqpow(ll a,ll b,ll mod)
//{
//    ll ans=1;
//    while(b)
//    {
//        if(b&1)
//            ans=exmod(ans*a,mod);
//        b>>=1;
//        a=exmod(a*a,mod);
//    }
//    return ans;
//}
//
//ll getphi(ll x)
//{
//    if(phi[x]!=-1)
//        return phi[x];
//    ll xx=x,ans=x;
//    for(ll i=2; i*i<=x; ++i)
//    {
//        if(x%i==0)
//        {
//            ans=ans*(i-1)/i;
//            while(x%i==0)
//                x/=i;
//        }
//    }
//    if(x>1)
//        ans=ans*(x-1)/x;
//    phi[xx]=ans;
//    return ans;
//}
//int n;//a[]的数量
//
//ll solve(int k,ll m)
//{
//    if(k==n||m==1)
//        return exmod(a[k],m);
//    return exqpow(a[k],solve(k+1,getphi(m)),m);
//}
//
//char s[110];
//
//
//int main()
//{
//    ll n,q,x;
//    scanf("%lld%lld",&n,&q);
//    while(q--)
//    {
//        scanf("%lld",&x);
//        if(n%2==1)
//        {
//            if(x<=n/2+1&&x%2==1)
//            {
//                printf("%d\n",x);
//                continue;
//            }
//        }
//        else
//        {
//            if(x<=n/2&&x%2==1)
//            {
//                printf("%d\n",x);
//                continue;
//            }
//        }
//
//            //
//        }
//    return 0;
//}

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

int main()
{
    long long n,k,x;
    cin>>n>>k;
    while(k--)
    {
        scanf("%lld",&x);
        if(x&1)
            printf("%lld\n",x/2+1);
        else
        {
            long long m=n;
            while(x%2==0)
            {
                x=m-x/2;
                m=x;
            }
            printf("%lld\n",n-x+(x)/2+1);
        }
    }
    return 0;
}


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

int main()
{
    long long n,k,x;
    cin>>n>>k;
    while(k--)
    {
        scanf("%lld",&x);
        if(x&1)
            printf("%lld\n",x/2+1);
        else
        {
            long long m=n;
            while(x%2==0)
            {
                x=m-x/2;
                m=x;
            }
            printf("%lld\n",n-x+(x+1)/2);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define printvector(v,n) for(int i=1;i<=n;i++) cout<<v[i]<<" "; cout<<ln;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for int64)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define RFOR(i,b,a) for(int i=b; i>=a; i--)
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define setPresent(x,s) (s.find(x)!=s.end())
typedef long long int64;
typedef pair<int,int> p32;
typedef pair<int64,int64> p64;
typedef pair<double,double> pdd;
typedef vector<int64> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
int64 n,q,x;
int64 f(int64 n,int64 x){
	if(n==1) return 1;
	if(n%2==0){
		return x%2 ? x/2+1 : n/2+f(n/2,x/2);
	}
	else{
		if(x%2==1) return x/2+1;
		else{
			if(x/2==1) return n/2+1+f(n/2,n/2);
			else return n/2+1+f(n/2,x/2-1);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin>>n>>q;
	FOR(i,1,q){
		cin>>x; cout<<f(n,x)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define printvector(v,n) for(int i=1;i<=n;i++) cout<<v[i]<<" "; cout<<ln;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for int64)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define RFOR(i,b,a) for(int i=b; i>=a; i--)
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define setPresent(x,s) (s.find(x)!=s.end())
typedef long long int64;
typedef pair<int,int> p32;
typedef pair<int64,int64> p64;
typedef pair<double,double> pdd;
typedef vector<int64> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
int64 n,q,x;
int64 f(int64 n,int64 x){
	if(n==1) return 1;
	if(n%2==0){
		return x%2 ? x/2+1 : n/2+f(n/2,x/2);
	}
	else{
		return x%2 ? x/2+1 : n/2+1+f(n/2,(x/2-1)%(n/2));
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin>>n>>q;
	FOR(i,1,q){
		cin>>x; cout<<f(n,x)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define printvector(v,n) for(int i=1;i<=n;i++) cout<<v[i]<<" "; cout<<ln;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for int64)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define RFOR(i,b,a) for(int i=b; i>=a; i--)
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define setPresent(x,s) (s.find(x)!=s.end())
typedef long long int64;
typedef pair<int,int> p32;
typedef pair<int64,int64> p64;
typedef pair<double,double> pdd;
typedef vector<int64> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
int64 n,q,x;
int64 f(int64 n,int64 x){
	if(n==1) return 1;
	if(n%2==0){
		return x%2 ? x/2+1 : n/2+f(n/2,x/2);
	}
	else{
		return x%2 ? x/2+1 : n/2+1+f(n/2,(x/2-1+n/2)%(n/2));
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin>>n>>q;
	FOR(i,1,q){
		cin>>x; cout<<f(n,x)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n, x, res, cnt, tot;
int q;
bool fir;
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%I64d%d", &n, &q);
	while (q--)
	{
		scanf("%I64d", &x);
		res = n, fir = true, cnt = 0;
		while (fir ^ (x & 1))
		{
			if (fir)
			{
				tot = (res + 1) / 2;
				x = x / 2;
				cnt += tot;
				res -= tot;
				if (tot > res) fir = false;
			}
			else
			{
				tot = res / 2;
				x = (x + 1) / 2;
				cnt += tot;
				res -= tot;
				if (tot == res) fir = true;
			}
		}
		printf("%I64d\n", cnt + (x + 1) / 2);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n, x, res, cnt, tot;
int q;
bool fir;
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%I64d%d", &n, &q);
	while (q--)
	{
		scanf("%I64d", &x);
		res = n, fir = true, cnt = 0;
		while (fir ^ (x & 1))
		{
			if (fir)
			{
				tot = (res + 1) / 2;
				x = x / 2;
				cnt += tot;
				res -= tot;
				if (tot > res) fir = false;
			}
			else
			{
				tot = res / 2;
				x = (x + 1) / 2;
				cnt += tot;
				res -= tot;
				if (tot != res) fir = true;
			}
		}
		printf("%I64d\n", cnt + (x + 1) / 2);
	}
	return 0;
}


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

map<pair<long long,long long>, long long> M;
long long que(long long n, long long x)
{
  if (x % 2 == 1)
    return (x+1) / 2;
  if (M.find(make_pair(n,x)) != M.end()) return M[make_pair(n,x)];
  return M[make_pair(n,x)] = que(n/2 + n%2, (x/2) + n%2) + (n/2);
}

int main()
{
  int n, q; scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++)
  {
    long long x; scanf("%lld", &x);
    printf("%lld\n", que(n, x));
  }
  return 0;
}


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

long long que(long long n, long long x)
{
  if ((x & 1LL) == 1)
    return ((x + 1) >> 1);
  return que((n >> 1) + (n & 1LL), (x >> 1) + (n & 1LL)) + (n >> 1);
}

int main()
{
  long long n, q; scanf("%lld%lld", &n, &q);
  for (int i = 1; i <= q; i++)
  {
    long long x; scanf("%lld", &x);
    printf("%lld\n", que(n, x));
  }
  return 0;
}


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

long long que(long long n, long long x)
{
  if (x % 2 == 1)
    return (x+1) / 2;
  return que((n>>1) + (n&1), (x>>1) + (n&1)) + (n>>1);
}

int main()
{
  int n, q; scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++)
  {
    long long x; scanf("%lld", &x);
    printf("%lld\n", que(n, x));
  }
  return 0;
}


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

long long que(long long n, long long x)
{
  if ((x&1LL) == 1)
    return ((x+1) >> 1);
  return que((n>>1) + (n&1LL), (x>>1) + (n&1LL)) + (n>>1);
}

int main()
{
  int n, q; scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++)
  {
    long long x; scanf("%lld", &x);
    printf("%lld\n", que(n, x));
  }
  return 0;
}


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

long long que(long long n, long long x)
{
  if (x % 2 == 1)
    return (x+1) / 2;
  return que(n/2 + n%2, (x/2) + n%2) + (n/2);
}

int main()
{
  int n, q; scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++)
  {
    long long x; scanf("%lld", &x);
    printf("%lld\n", que(n, x));
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll sol(ll x, ll n, ll lg) {
//	cout << x << " " << n << " " << lg << endl;
	if (n == (1ll << lg)) {
		if (x % 2 == 1)
			return (x + 1) / 2;
//		cout
		return n / 2 + sol(x / 2, n / 2, lg - 1);
	} else {
		ll l = 2 * (n - (1ll << lg));
		//cout << "else " << l << " " << x - l + 1 << endl;
		if (x % 2 == 1 && x <= l)
			return (x + 1) / 2;
		if (x <= l) {
			return (l / 2) + sol(n - l + x / 2, (1ll << lg), lg);
		} else {
			return (l / 2) + sol(x - l, (1ll << lg), lg);
		}
	}
}

int main() {
//    fin("t.in");
//    fout("t.out");
    srand(time(0));
    sync;
    ll n, lg;
    int Q;
	cin >> n >> Q;
	lg = 0;
	while ((2ll << lg) <= n)
		++lg;
	F(numq, 0, Q) {
		ll x;
		cin >> x;
//		x = ((ll)rand() << 16) + rand();
		cout << sol(x, n, lg) << "\n";
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll sol(ll x, ll n, ll lg) {
	while ((1ll << lg) > n)
		--lg;
//	cout << x << " " << n << " " << lg << endl;
	if (n == (1 << lg)) {
		if (x % 2 == 1)
			return (x + 1) / 2;
//		cout
		return n / 2 + sol(x / 2, n / 2, lg - 1);
	} else {
		ll l = 2 * (n - (1ll << lg));
		//cout << "else " << l << " " << x - l + 1 << endl;
		if (x % 2 == 1 && x <= l)
			return (x + 1) / 2;
		if (x <= l) {
			return (l / 2) + sol(n - l + x / 2, (1 << lg), lg);
		} else {
			return (l / 2) + sol(x - l, (1 << lg), lg);
		}
	}
}

int main() {
//    fin("t.in");
    sync;
    ll n, lg;
    int Q;
	cin >> n >> Q;
	lg = 0;
	while ((2ll << lg) <= n)
		++lg;
	F(numq, 0, Q) {
		ll x;
		cin >> x;
		cout << sol(x, n, lg) << "\n";
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll sol(ll x, ll n, ll lg) {
	while ((1ll << lg) > n)
		--lg;
//	cout << x << " " << n << " " << lg << endl;
	if (n == (1ll << lg)) {
		if (x % 2 == 1)
			return (x + 1) / 2;
//		cout
		return n / 2 + sol(x / 2, n / 2, lg - 1);
	} else {
		ll l = 2 * (n - (1ll << lg));
		//cout << "else " << l << " " << x - l + 1 << endl;
		if (x % 2 == 1 && x <= l)
			return (x + 1) / 2;
		if (x <= l) {
			return (l / 2) + sol(n - l + x / 2, (1 << lg), lg);
		} else {
			return (l / 2) + sol(x - l, (1 << lg), lg);
		}
	}
}

int main() {
//    fin("t.in");
    sync;
    ll n, lg;
    int Q;
	cin >> n >> Q;
	lg = 0;
	while ((2ll << lg) <= n)
		++lg;
	F(numq, 0, Q) {
		ll x;
		cin >> x;
		cout << sol(x, n, lg) << "\n";
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n;

int main()
{
	long long t,rr,i,k,w;

	scanf("%lld%lld",&n,&t);
	for(rr=0;rr<t;rr++)
	{
		scanf("%lld",&k);
		for(w=n;1;k=w)
		{
			w-=k/2;
			if(k%2)
			{
				break;
			}
		}
		printf("%lld\n",n+1-w);
	}
}


#include <bits/stdc++.h>

using namespace std;

long long n;

long long dfs(int x)
{
    if(x%2)
        return (x+1)/2;
    else return dfs(n+x/2);
}

int main()
{
//    long long n;
    int q;
    while(cin >> n >> q)
    {
        for(int i=1;i<=q;i++)
        {
            long long x;
            cin >> x;
            cout << dfs(x) << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n;

long long dfs(long long x)
{
    if(x%2)
        return (x+1)/2;
    else return dfs(n+x/2);
}

int main()
{
//    long long n;
    int q;
    while(cin >> n >> q)
    {
        for(int i=1;i<=q;i++)
        {
            long long x;
            cin >> x;
            cout << dfs(x) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,q;
    cin >> n >> q;
    while(q--) {
        long long pos;
        cin >> pos;
        if(pos & 1) {
            cout << (pos / 2) + 1 << endl;
        }else {
            int x = n - 1 - pos / 2 + 1;// the x-th space
            while(!(pos & 1)) {
                pos += x;
                if(!(pos & 1)) {
                    x = n - 1 - pos / 2 + 1;
                }
            }
            cout << (pos / 2) + 1 << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,q;
    cin >> n >> q;
    while(q--) {
        long long pos;
        cin >> pos;
        if(pos & 1) {
            cout << (pos / 2) + 1 << endl;
        }else {
            long long x = n - 1 - pos / 2 + 1;// the x-th space
            while(!(pos & 1)) {
                pos += x;
                if(!(pos & 1)) {
                    x = n - 1 - pos / 2 + 1;
                }
            }
            cout << (pos / 2) + 1 << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int) (x).size())
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int read() {
	int x = 0, f = 1;char ch;
	for (ch = getchar(); !isdigit(ch); ch = getchar())
		if (ch == '-') f = -1;
	for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

LL n; int q;

LL f(LL n, LL x) {
	if(x & 1)
		return x + 1 >> 1;
	LL cur = n + 1 >> 1;
	if(n & 1)if(x == 2)
		return cur + f(n >> 1, n >> 1);
	return cur + ((n & 1) ? f(n >> 1, (x >> 1) - 1) : f(n >> 1, x >> 1));
}

int main() {
	scanf("%lld%d\n", &n, &q);
	while(q--) {
		LL x; scanf("%lld", &x);
		printf("%lld\n", f(n, x));
	}
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int) (x).size())
#define ALL(x) x.begin(), x.end()

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int read() {
	int x = 0, f = 1;char ch;
	for (ch = getchar(); !isdigit(ch); ch = getchar())
		if (ch == '-') f = -1;
	for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

LL n; int q;

LL f(LL n, LL x) {
	if(x & 1)
		return x + 1 >> 1;
	LL cur = n + 1 >> 1;
	if(x == 2)
		return cur + f(n >> 1, n >> 1);
	return cur + ((n & 1) ? f(n >> 1, (x >> 1) - 1) : f(n >> 1, x >> 1));
}

int main() {
	scanf("%lld%d\n", &n, &q);
	while(q--) {
		LL x; scanf("%lld", &x);
		printf("%lld\n", f(n, x));
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long i,j,k,l,n,m;

long long count(long long k){
    if(k%2!=0)return k/2+1;

    long long d=k/2;

    return count(n-d)+d;
}

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

    for(i=1;i<=m;i++){
        cin>>k;
        cout<<count(k)<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long i,j,k,l,n,m;

long long count(long long n,long long k){
    if(k%2!=0)return k/2+1;

    long long d=k/2;
    return count(n-d,n-d)+d;
}

int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>k;
        cout<<count(n,k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=200005;
ll n,a[MAXN],m,ans[MAXN],cur,s,Add,w;
int q,f;
ll Count(int i,ll m){return ((n-m-1)>>i)+1;}
int main(){
	scanf("%I64d%d",&n,&q);
	for(int i=1;i<=q;i++)scanf("%lld",&a[i]),a[i]--;
	f=0,m=0,cur=0;
	for(int i=0;cur<n;i++){
		s=Count(i,m);
		w=m+(f<<i);
		for(int j=1;j<=q;j++)if(!ans[j]&&w==(a[j]&((1<<i+1)-1)))ans[j]=cur+(a[j]>>(i+1))+1;
		m+=(f^1)<<i;
		Add=(s-f+1)>>1;
		cur+=Add;
		f^=s&1;
	}
	for(int i=1;i<=q;i++)printf("%I64d\n",ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=200005;
ll n,a[MAXN],m,ans[MAXN],cur,s,Add,w,f;
int q;
ll Count(int i,ll m){return ((n-m-1)>>i)+1;}
int main(){
	scanf("%I64d%d",&n,&q);
	for(int i=1;i<=q;i++)scanf("%lld",&a[i]),a[i]--;
	f=0,m=0,cur=0;
	for(int i=0;cur<n;i++){
		s=Count(i,m);
		w=m+(f<<i);
		for(int j=1;j<=q;j++)if(!ans[j]&&w==(a[j]&((1ll<<(i+1))-1)))ans[j]=cur+(a[j]>>(i+1))+1;
		m+=(f^1)<<i;
		Add=(s-f+1)>>1;
		cur+=Add;
		f^=s&1;
	}
	for(int i=1;i<=q;i++)printf("%I64d\n",ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll readll(){
	ll x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}

ll n,q,m,cnt;
ll bin[100];

int main(){
	n = readll(); q = readll(); m = 2*n-1;
	while(m >= n){
		if(m >= (1<<cnt)) bin[++cnt] = m,m -= (1<<cnt);
	}
	bin[++cnt] = m;
	while(q--){
		ll x = read(); ll p = cnt; m = n;
		while(x%2 == 0 && x != (n-1)*2){
			x = bin[p-1]-(bin[p]-x+1)/2;
			--p;
		}
		if(x%2 == 0) ++x;
		printf("%lld\n", (x+1)/2);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll readll(){
	ll x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}

ll n,q,m,cnt;
ll bin[100];

int main(){
	n = readll(); q = readll(); m = 2*n-1;
	while(m >= n){
		if(m >= (1LL<<cnt)) bin[++cnt] = m,m -= (1LL<<cnt);
	}
	bin[++cnt] = m;
	while(q--){
		ll x = readll(); ll p = cnt; m = n;
		while(x%2 == 0 && x != (n-1)*2){
			x = bin[p-1]-(bin[p]-x+1)/2;
			--p;
		}
		if(x%2 == 0) ++x;
		printf("%lld\n", (x+1)/2);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll readll(){
	ll x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}

ll n,q,m,cnt;
ll bin[100];

int main(){
	n = readll(); q = readll(); m = 2*n-1;
	while(m >= n){
		if(m >= (1<<cnt)) bin[++cnt] = m,m -= (1<<cnt);
	}
	bin[++cnt] = m;
	while(q--){
		ll x = readll(); ll p = cnt; m = n;
		while(x%2 == 0 && x != (n-1)*2){
			x = bin[p-1]-(bin[p]-x+1)/2;
			--p;
		}
		if(x%2 == 0) ++x;
		printf("%lld\n", (x+1)/2);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 200009
#define MAXM 320
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

ll calc(ll n, ll val, ll s) {
	if (n == 0 || (s+val)%2) return s + (val + 1)/2;
	return calc(n/2, val/2, s + (n+1)/2);
}
int main() {
	ll n, val, q;
	cin >> n >> q;
	while(q--) {
		scanf("%I64d", &val);
		printf("%I64d\n", calc(n, val, 0));
	}
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 200009
#define MAXM 320
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

ll rec(ll n, ll val) {
	if (n == 1 || val%2 == 0) return (val+1)/2;
	if (n%2 == 1 && val == n) return rec((n+1)/2, 1) + n/2;
	return rec((n+1)/2, (val+1)/2 + ((n)%2)) + n/2;
}
ll calc(ll n, ll val) {
	if (val%2) return (val + 1)/2;
	if (n%2 == 0 && val == n) return rec(n/2, 1) + (n+1)/2;
	return rec(n/2, val/2 + ((n+1)%2)) + (n+1)/2;
}

void simulate(ll n) {
	vector<ll> vec;
	vec.pb(1);
	for(int i = 2; i <= n; i++) {
		vec.pb(0); vec.pb(i);
	}

	while((ll)vec.size() > n) {
		for (int k = (int)vec.size()-1; k >= 0; k--) {
			if (vec[k] == 0) {
				vec[k] = vec.back();
				vec.pop_back();
				break;
			}
		}
	}
}
int main() {
	ll n, val, q;
	cin >> n >> q;
//	simulate(n);
	while(q--) {
		scanf("%I64d", &val);
		printf("%I64d\n", calc(n, val));
	}
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 200009
#define MAXM 320
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

ll rec(ll n, ll val) {
	if (n == 1 || val%2 == 0) return val/2;
	if (val == n) return rec((n+1)/2, 1) + n/2;
	return rec((n+1)/2, (val+1)/2 + 1) + n/2;
}
ll calc(ll n, ll val) {
	if (val%2) return (val + 1)/2;
	if (val == n) return rec(n/2, 1) + (n+1)/2;
	return rec(n/2, val/2 + 1) + (n+1)/2;
}

void simulate(ll n) {
	vector<ll> vec;
	vec.pb(1);
	for(int i = 2; i <= n; i++) {
		vec.pb(0); vec.pb(i);
	}

	while((ll)vec.size() > n) {
		for (int k = (int)vec.size()-1; k >= 0; k--) {
			if (vec[k] == 0) {
				vec[k] = vec.back();
				vec.pop_back();
				break;
			}
		}
	}
}
int main() {
	ll n, val, q;
	cin >> n >> q;
//	simulate(n);
	while(q--) {
		scanf("%I64d", &val);
		printf("%I64d\n", calc(n, val));
	}
}


#include<cstdio>
long long n,Q;
long long x;
int main()
{
	scanf("%lld%lld",&n,&Q);
	while(Q--)
	{
		scanf("%lld",&x);
		while(!(x&1))
			x+=n-x/2;
		printf("%lld\n",(x-1)/2+1);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read () { LL res = 0 ;int f (1) ;char ch = getchar ();
	while (!isdigit(ch)) { if (ch == '-') f = -1 ;ch = getchar();}
	while (isdigit(ch)) res = (res << 1) + (res << 3) + (ch ^ 48) ,ch = getchar(); return res * f ;
}
LL n;
int q;
signed main () {
	n=read();
	q=read();
	while(q--) {
		LL x=read();
		while(1) {
			if(x&1) break;
			x += (n - (x >> 1)) ;
		}
		cout << ((x-1) >> 1) + 1 << endl ;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    //freopen("input.in","r",stdin);

    long long n;
    int q;
    cin >> n >> q;

    while(q--)
    {
        long long x;
        cin >> x;
        while(1)
        {
            if(x % 2 == 1) break;
            x = x + (n - x / 2);
        }
        cout << (x - 1) / 2 + 1 << endl;
    }
    return 0;
}


#include<cstdio>
#define ll long long
using namespace std;
int main() {
	ll n,q,x;
	scanf("%lld%lld",&n,&q);
	while(q--) {
		scanf("%lld",&x);
		if(x%2) printf("%lld\n",x/2+1);
		else {
			ll m=n;
			while(x%2 == 0) {
				x = m - x/2;
				m = x;
			}
			printf("%lld\n",(x/2+1)+n-m);
		}
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<math.h>
#include<utility>
#include<set>
using namespace std;
#define fi first
#define sc second
#define ll long long
#define pb push_back
#define INF 0x3f3f3f3f
#define ls 2*tr
#define rs 2*tr+1
#define N 100010
ll re()
{
    ll x;
    scanf("%lld",&x);
    return x;
}
int main()
{
    ll n,q;
    cin>>n>>q;
    ll e=(n+1)/2;
    while(q--)
    {
        ll x=re();
        if((x+1)/2<=e&&(x&1)) cout<<(x+1)/2<<endl;
        else
        {
            if(x&1)
            {
                x++;
                ll s=(2*n-x)/2;
                x=x-1+s;
                cout<<(x+1)/2<<endl;
            }
            else
            {
                ll s=(2*n-x)/2;
                ll now=x;
                while(!(s&1))
                {
                    now+=s;
                    s/=2;
                }
                now+=s;
                cout<<(now+1)/2<<endl;
            }
        }
    }
}


#include <iostream>
using namespace std;

int main(){
long long int n,x=0,q;
cin >>n>>q;
	while (q--)
	{
		cin>>x;
		while (x%2==0) x=x/2+n;
		cout<<(x+1)/2<<endl;
	}
	return 0;
}


//
//  main.cpp
//  code
//
//  Created by Harsh Varshney on 10/03/18.
//  Copyright © 2018 Harsh Varshney. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    long long int n;
    int q;
    cin>>n>>q;
    vector<long long int>v ;
    for(int i=1; i<=n; i++){
        v.push_back(i);
        v.push_back(0);
    }
    v.pop_back();

    cout<<endl;
    long long int x=v.size()-1;
    long long int y = v.size()-2;
    while(y>0){
        swap(v[x],v[y]);
        x--;
        y-=2;
    }

    for(int i=0; i<q; i++){
        long long int temp;
        cin>>temp;
        cout<<v[temp-1]<<endl;
    }
    return 0;
}


//
//  main.cpp
//  code
//
//  Created by Harsh Varshney on 10/03/18.
//  Copyright © 2018 Harsh Varshney. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    long long int n;
    int q;
    cin>>n>>q;
    if(n==1){
        cout<<"1";
        return 0;
    }
    vector<long long int>v ;
    for(int i=1; i<=n; i++){
        v.push_back(i);
        v.push_back(0);
    }
    v.pop_back();

    cout<<endl;
    long long int x=v.size()-1;
    long long int y = v.size()-2;
    while(y>0){
        swap(v[x],v[y]);
        x--;
        y-=2;
    }

    for(int i=0; i<q; i++){
        long long int temp;
        cin>>temp;
        cout<<v[temp-1]<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main(){
long int n,x=0,q;
cin >>n>>q;
	while (q--)
	{
		cin>>x;
		while (x%2==0) x=x/2+n;
		cout<<(x+1)/2<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main(){
int n,x=0,q;
cin >>n>>q;
	while (q--)
	{
		cin>>x;
		while (x%2==0) x=x/2+n;
		cout<<(x+1)/2<<endl;
	}
	return 0;
}


const readline = require('readline');
const fs = require('fs')
const rl = readline.createInterface({
   input: process.stdin,
//   input : fs.createReadStream('practice/codeforces/test.in'),
  output: process.stdout
});
num = 0
rl.on('line', str => {
  if (num == 0) {
    num = str
  } else {
    func(str)
  }
});
isdigit = a => a <= 9 && a >= 0
isLower = a => a <= 'z' && a >= 'a'
isUpper = a => a <= 'Z' && a >= 'A'
function func(str) {
  n = 0;
  l = 0;
  u = 0;
  for (char of str) {
    if (isdigit(char)) {
      n += 1
    } else if (isLower(char)) {
      l += 1
    } else if (isUpper(char)) {
      u += 1
    }
  }
  if (n && l && u) {
    console.log(str)
    return;
  }
  if (n == 0 && l == 0) {
    console.log('1a' + str.slice(2))
  } else if (n == 0 && u == 0) {
    console.log('1A' + str.slice(2))
  } else if (l == 0 && u == 0) {
    console.log('aA' + str.slice(2))
  }
  else {
    if (n == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isUpper(str[0]) && isUpper(str[1])) ) {
        console.log('1' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + '1' + str.slice(3))
      }
    }else if (l == 0) {
      if ((isdigit(str[0]) && isdigit(str[1])) ||
        (isUpper(str[0]) && isUpper(str[1]))
      ) {
        console.log('a' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'a' + str.slice(3))
      }
    } else if (u == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isdigit(str[0]) && isdigit(str[1]))
      ) {
        console.log('A' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'A' + str.slice(3))
      }
    }
  }
}


const readline = require('readline');
const fs = require('fs')
const rl = readline.createInterface({
  input: process.stdin,
  // input : fs.createReadStream('practice/codeforces/test.in'),
  output: process.stdout
});
num = 0
rl.on('line', str => {
  if (num == 0) {
    num = str
  } else {
    func(str)
  }
});
isdigit = a => a <= 9 && a >= 0
isLower = a => a <= 'z' && a >= 'a'
isUpper = a => a <= 'Z' && a >= 'A'
function func(str) {
  n = 0;
  l = 0;
  u = 0;
  for (char of str) {
    if (isdigit(char)) {
      n += 1
    } else if (isLower(char)) {
      l += 1
    } else if (isUpper(char)) {
      u += 1
    }
  }
  if (n && l && u) {
    console.log(str)
    return;
  }
  if (n == 0 && l == 0) {
    console.log('1a' + str.slice(2))
  } else if (n == 0 && u == 0) {
    console.log('1A' + str.slice(2))
  } else if (l == 0 && u == 0) {
    console.log('aA' + str.slice(2))
  }
  else {
    if (n == 0) {
      if (isLower(str[0]) && isLower(str[1])) {
        console.log('1' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + '1' + str.slice(3))
      }
    }else if (l == 0) {
      if (isdigit(str[0]) && isdigit(str[1])) {
        console.log('a' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'a' + str.slice(3))
      }
    } else if (u == 0) {
      if (isLower(str[0]) && isLower(str[1])) {
        console.log('A' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'A' + str.slice(3))
      }
    }
  }
}


const readline = require('readline');
const fs = require('fs')
const rl = readline.createInterface({
   input: process.stdin,
//   input : fs.createReadStream('practice/codeforces/test.in'),
  output: process.stdout
});
num = 0
rl.on('line', str => {
  if (num == 0) {
    num = str
  } else {
    func(str)
  }
});
isdigit = a => a <= 9 && a >= 0
isLower = a => a <= 'z' && a >= 'a'
isUpper = a => a <= 'Z' && a >= 'A'
function func(str) {
  n = 0;
  l = 0;
  u = 0;
  for (char of str) {
    if (isdigit(char)) {
      n += 1
    } else if (isLower(char)) {
      l += 1
    } else if (isUpper(char)) {
      u += 1
    }
  }
  if (n && l && u) {
    console.log(str)
    return;
  }
  if (n == 0 && l == 0) {
    console.log('1a' + str.slice(2))
  } else if (n == 0 && u == 0) {
    console.log('1A' + str.slice(2))
  } else if (l == 0 && u == 0) {
    console.log('aA' + str.slice(2))
  }
  else {
    if (n == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isUpper(str[0]) && isUpper(str[1])) ) {
        console.log('1' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + '1' + str.slice(3))
      }
    }else if (l == 0) {
      if ((isdigit(str[0]) && isdigit(str[1])) ||
        (isUpper(str[0]) && isUpper(str[0]))
      ) {
        console.log('a' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'a' + str.slice(3))
      }
    } else if (u == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isdigit(str[0]) && isdigit(str[0]))
      ) {
        console.log('A' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'A' + str.slice(3))
      }
    }
  }
}


const readline = require('readline');
const fs = require('fs')
const rl = readline.createInterface({
  // input: process.stdin,
  input : fs.createReadStream('practice/codeforces/test.in'),
  output: process.stdout
});
num = 0
rl.on('line', str => {
  if (num == 0) {
    num = str
  } else {
    func(str)
  }
});
isdigit = a => a <= 9 && a >= 0
isLower = a => a <= 'z' && a >= 'a'
isUpper = a => a <= 'Z' && a >= 'A'
function func(str) {
  n = 0;
  l = 0;
  u = 0;
  for (char of str) {
    if (isdigit(char)) {
      n += 1
    } else if (isLower(char)) {
      l += 1
    } else if (isUpper(char)) {
      u += 1
    }
  }
  if (n && l && u) {
    console.log(str)
    return;
  }
  if (n == 0 && l == 0) {
    console.log('1a' + str.slice(2))
  } else if (n == 0 && u == 0) {
    console.log('1A' + str.slice(2))
  } else if (l == 0 && u == 0) {
    console.log('aA' + str.slice(2))
  }
  else {
    if (n == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isUpper(str[0]) && isUpper(str[1])) ) {
        console.log('1' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + '1' + str.slice(3))
      }
    }else if (l == 0) {
      if ((isdigit(str[0]) && isdigit(str[1])) ||
        (isUpper(str[0]) && isUpper(str[0]))
      ) {
        console.log('a' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'a' + str.slice(3))
      }
    } else if (u == 0) {
      if ((isLower(str[0]) && isLower(str[1])) ||
      (isdigit(str[0]) && isdigit(str[0]))
      ) {
        console.log('A' + str.slice(1))
      } else {
        console.log(str.slice(0,2) + 'A' + str.slice(3))
      }
    }
  }
}


using System;
using System.Linq;

namespace CSharp
{
    class _1051A
    {
        public static void Main()
        {
            for (int n = int.Parse(Console.ReadLine()); n > 0; n--)
            {
                var s = Console.ReadLine().ToCharArray();

                int count = 0;

                if (s.Any(c => char.IsLetter(c) && char.IsLower(c)))
                {
                    count++;
                }

                if (s.Any(c => char.IsLetter(c) && char.IsUpper(c)))
                {
                    count++;
                }

                if (s.Any(c => char.IsDigit(c)))
                {
                    count++;
                }

                switch (count)
                {
                    case 1:
                        if (char.IsDigit(s[0]))
                        {
                            s[0] = 'a';
                            s[1] = 'A';
                        }
                        else if (char.IsLower(s[0]))
                        {
                            s[0] = '0';
                            s[1] = 'A';
                        }
                        else
                        {
                            s[0] = '0';
                            s[1] = 'a';
                        }

                        break;
                    case 2:
                        int digitCount = 0;
                        int lowerCount = 0;
                        int upperCount = 0;

                        for (int i = 0; i < 3; i++)
                        {
                            if (char.IsDigit(s[i]))
                            {
                                digitCount++;
                            }
                            else if (char.IsLower(s[i]))
                            {
                                lowerCount++;
                            }
                            else
                            {
                                upperCount++;
                            }
                        }

                        int index = Enumerable.Range(0, s.Length).First(i => digitCount == 2 ? char.IsDigit(s[i]) : char.IsLetter(s[i]) && (lowerCount == 2 ? char.IsLower(s[i]) : char.IsUpper(s[i])));
                        s[index] = digitCount == 0 ? '0' : lowerCount == 0 ? 'a' : 'A';

                        break;
                }

                Console.WriteLine(new string(s));
            }
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    class _1051A
    {
        public static void Main()
        {
            for (int n = int.Parse(Console.ReadLine()); n > 0; n--)
            {
                var s = Console.ReadLine().ToCharArray();

                int count = 0;

                if (s.Any(c => char.IsLetter(c) && char.IsLower(c)))
                {
                    count++;
                }

                if (s.Any(c => char.IsLetter(c) && char.IsUpper(c)))
                {
                    count++;
                }

                if (s.Any(c => char.IsDigit(c)))
                {
                    count++;
                }

                switch (count)
                {
                    case 1:
                        if (char.IsDigit(s[0]))
                        {
                            s[0] = 'a';
                            s[1] = 'A';
                        }
                        else if (char.IsLower(s[0]))
                        {
                            s[0] = '0';
                            s[1] = 'A';
                        }
                        else
                        {
                            s[0] = '0';
                            s[1] = 'a';
                        }

                        break;
                    case 2:
                        int digitCount = 0;
                        int lowerCount = 0;
                        int upperCount = 0;

                        for (int i = 0; i < s.Length; i++)
                        {
                            if (char.IsDigit(s[i]))
                            {
                                digitCount++;
                            }
                            else if (char.IsLower(s[i]))
                            {
                                lowerCount++;
                            }
                            else
                            {
                                upperCount++;
                            }
                        }

                        int index = Enumerable.Range(0, s.Length).First(i => digitCount > 1 ? char.IsDigit(s[i]) : char.IsLetter(s[i]) && (lowerCount > 1 ? char.IsLower(s[i]) : char.IsUpper(s[i])));
                        s[index] = digitCount == 0 ? '0' : lowerCount == 0 ? 'a' : 'A';

                        break;
                }

                Console.WriteLine(new string(s));
            }
        }
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < t; i++)
        {
            Q(sc);
        }
        Console.Out.Flush();
    }

    void Q(Scanner sc)
    {
        string s = sc.Next();
        // パスワード
        // 1つ数字、大小文字
        var c = s.ToArray();

        int num = 0;
        int up = 0;
        int low = 0;

        foreach (char ch in s)
        {
            if ('0' <= ch && ch <= '9') num++;
            if ('a' <= ch && ch <= 'z') low++;
            if ('A' <= ch && ch <= 'Z') up++;
        }

        for (int i = 0; i < s.Length; i++)
        {
            var ch = s[i];
            bool u = 'A' <= ch && ch <= 'Z';
            bool l = 'a' <= ch && ch <= 'z';
            bool n = '0' <= ch && ch <= '9';
            if (num == 0)
            {
                if (u && up > 1)
                {
                    up--;
                    num++;
                    c[i] = '1';
                }
                else if (l && low > 1)
                {
                    low--;
                    num++;
                    c[i] = '1';
                }
            }

            if (up == 0)
            {
                if (n && num > 1)
                {
                    num--;
                    up++;
                    c[i] = 'A';
                }
                else if (l && low > 1)
                {
                    low--;
                    up++;
                    c[i] = 'A';
                }
            }

            if (low == 0)
            {
                if (u && up > 1)
                {
                    up--;
                    low++;
                    c[i] = 'a';
                }
                else if (n && num > 1)
                {
                    num--;
                    low++;
                    c[i] = 'a';
                }
            }
        }
        Console.WriteLine(new string(c));

    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < t; i++)
        {
            Q(sc);
        }
        Console.Out.Flush();
    }

    void Q(Scanner sc)
    {
        string s = sc.Next();
        int low = 0;
        int up = 0;
        int num = 0;
        foreach (var c in s)
        {
            if ('0' <= c && c <= '9') num++;
            if ('a' <= c && c <= 'z') low++;
            if ('A' <= c && c <= 'Z') up++;
        }

        if (num > 0 && low > 0 && up > 0)
        {
            Console.WriteLine(s);
            return;
        }

        char[] ar = s.ToCharArray();
        // 1種
        if (low == s.Length)
        {
            ar[0] = '1';
            ar[1] = 'A';
        }
        else if (up == s.Length)
        {
            ar[0] = '1';
            ar[1] = 'a';
        }
        else if (num == s.Length)
        {
            ar[0] = 'a';
            ar[1] = 'A';
        }
        else
        {
            // 2種
            for (int i = 0; i < s.Length; i++)
            {
                bool u = 'A' <= s[i] && s[i] <= 'Z';
                bool l = 'a' <= s[i] && s[i] <= 'z';
                bool n = '0' <= s[i] && s[i] <= '9';
                if (u && up >= 2)
                {
                    if (num == 0)
                    {
                        ar[i] = '1';
                        break;
                    }
                    else if (low == 0)
                    {
                        ar[i] = 'a';
                        break;
                    }
                }

                if (l && low >= 2)
                {
                    if (num == 0)
                    {
                        ar[i] = '1';
                        break;
                    }
                    else if (up == 0)
                    {
                        ar[i] = 'A';
                        break;
                    }
                }

                if (n && num >= 2)
                {
                    if (up == 0)
                    {
                        ar[i] = 'A';
                        break;
                    }
                    else if (low == 0)
                    {
                        ar[i] = 'a';
                        break;
                    }
                }
            }
        }

        Console.WriteLine(new string(ar));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = Convert.ToInt32(Console.ReadLine());

            List<string> answers = new List<string>();

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine();

                if (!s.Any(Char.IsUpper))
                {
                    if (s.Any(Char.IsLower))
                    {
                        if (s.Count(Char.IsLower) > 1)
                        {
                            if (!s.Any(Char.IsDigit))
                            {
                                answers.Add(s.Remove(0, 2).Insert(0, "A1"));
                            }
                            else
                            {
                                if (s.Count(Char.IsDigit) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsLower(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                                break;
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j, "A"));
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int j = 0; j < s.Length; j++)
                            {
                                if (Char.IsDigit(s[j]))
                                {
                                    if (j == 0)
                                    {
                                        answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                    }
                                    else
                                    {
                                        answers.Add(s.Remove(j, 1).Insert(j, "A"));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        answers.Add(s.Remove(0, 2).Insert(0, "Aa"));
                    }
                }
                else
                {
                    if (!s.Any(Char.IsLower))
                    {
                        if (s.Any(Char.IsDigit))
                        {
                            if (s.Count(Char.IsDigit) > 1)
                            {
                                if (s.Count(Char.IsUpper) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsDigit(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j, "a"));
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < s.Length; j++)
                                {
                                    if (Char.IsUpper(s[j]))
                                    {
                                        if (j == 0)
                                        {
                                            answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                        }
                                        else
                                        {
                                            answers.Add(s.Remove(j, 1).Insert(j, "a"));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            answers.Add(s.Remove(0, 2).Insert(0, "1a"));
                        }
                    }
                    else
                    {
                        if (!s.Any(Char.IsDigit))
                        {
                            if (s.Count(Char.IsLower) > 1)
                            {
                                if (s.Count(Char.IsUpper) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsLower(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j, "1"));
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < s.Length; j++)
                                {
                                    if (Char.IsUpper(s[j]))
                                    {
                                        if (j == 0)
                                        {
                                            answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                        }
                                        else
                                        {
                                            answers.Add(s.Remove(j, 1).Insert(j, "1"));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            answers.Add(s);
                        }
                    }
                }
            }

            for (int i = 0; i < answers.Count; i++)
            {
                Console.WriteLine(answers[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = Convert.ToInt32(Console.ReadLine());

            List<string> answers = new List<string>();

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine();

                if (!s.Any(Char.IsUpper))
                {
                    if (s.Any(Char.IsLower))
                    {
                        if (s.Count(Char.IsLower) > 1)
                        {
                            if (!s.Any(Char.IsDigit))
                            {
                                answers.Add(s.Remove(0, 2).Insert(0, "A1"));
                            }
                            else
                            {
                                if (s.Count(Char.IsDigit) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsLower(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                                break;
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j - 1, "A"));
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int j = 0; j < s.Length; j++)
                            {
                                if (Char.IsDigit(s[j]))
                                {
                                    if (j == 0)
                                    {
                                        answers.Add(s.Remove(0, 1).Insert(0, "A"));
                                    }
                                    else
                                    {
                                        answers.Add(s.Remove(j, 1).Insert(j - 1, "A"));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        answers.Add(s.Remove(0, 2).Insert(0, "Aa"));
                    }
                }
                else
                {
                    if (!s.Any(Char.IsLower))
                    {
                        if (s.Any(Char.IsDigit))
                        {
                            if (s.Count(Char.IsDigit) > 1)
                            {
                                if (s.Count(Char.IsUpper) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsDigit(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j - 1, "a"));
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < s.Length; j++)
                                {
                                    if (Char.IsUpper(s[j]))
                                    {
                                        if (j == 0)
                                        {
                                            answers.Add(s.Remove(0, 1).Insert(0, "a"));
                                        }
                                        else
                                        {
                                            answers.Add(s.Remove(j, 1).Insert(j - 1, "a"));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            answers.Add(s.Remove(0, 2).Insert(0, "1a"));
                        }
                    }
                    else
                    {
                        if (!s.Any(Char.IsDigit))
                        {
                            if (s.Count(Char.IsLower) > 1)
                            {
                                if (s.Count(Char.IsUpper) > 1)
                                {
                                    answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                }
                                else
                                {
                                    for (int j = 0; j < s.Length; j++)
                                    {
                                        if (Char.IsLower(s[j]))
                                        {
                                            if (j == 0)
                                            {
                                                answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                            }
                                            else
                                            {
                                                answers.Add(s.Remove(j, 1).Insert(j - 1, "1"));
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < s.Length; j++)
                                {
                                    if (Char.IsUpper(s[j]))
                                    {
                                        if (j == 0)
                                        {
                                            answers.Add(s.Remove(0, 1).Insert(0, "1"));
                                        }
                                        else
                                        {
                                            answers.Add(s.Remove(j, 1).Insert(j - 1, "1"));
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            answers.Add(s);
                        }
                    }
                }
            }

            for (int i = 0; i < answers.Count; i++)
            {
                Console.WriteLine(answers[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Schet(string a,out int big,out int smal,out int cif)
        {
            big = 0;
            smal = 0;
            cif = 0;
            foreach(char b in a)
            {
                if (char.IsUpper(b)) big += 1;
                if (char.IsLower(b)) smal += 1;
                if (char.IsDigit(b)) cif += 1;
            }
        }
        static void Izmen(int big,int smal,int cif,string pas,out string zam)
        {
            zam = pas;
            if (big == 0 || smal == 0 || cif == 0) {
                char[] pasmas = pas.ToArray<char>();
                int n = pasmas.Length;
                if (big == 0 & smal == 0 & cif != 0) {
                    pasmas[0] = Convert.ToChar("A");
                    pasmas[1] = Convert.ToChar("a");
                    zam = new string(pasmas);
                }
                if (big == 0 & cif == 0 & smal != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToUpper());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal == 0 & big != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToLower());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (big == 0 & smal != 0 & cif != 0) {
                    if (smal > 1) {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsLower(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("A");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (smal == 0 & cif != 0 & big != 0) {
                    if (big > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsUpper(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToLower());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("a");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal != 0 & big != 0) {
                    if (smal > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsLower(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsUpper(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
            }
        }
        static void Main(string[] args)
        {
            int T = Convert.ToInt32(Console.ReadLine());
            string[] pasv = new string[T];
            for (int i = 0; i < T; i++)
            {
                pasv[i] = Console.ReadLine();
                Schet(pasv[i], out int big, out int smal, out int cif);
                Izmen(big, smal, cif, pasv[i], out string zam);
                pasv[i] = zam;
            }
            for (int i = 0; i < T; i++)
            {
                Console.WriteLine(pasv[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Schet(string a,out int big,out int smal,out int cif)
        {
            big = 0;
            smal = 0;
            cif = 0;
            foreach(char b in a)
            {
                if (char.IsUpper(b)) big += 1;
                if (char.IsLower(b)) smal += 1;
                if (char.IsDigit(b)) cif += 1;
            }
        }
        static void Izmen(int big,int smal,int cif,string pas,out string zam)
        {
            zam = pas;
            if (big == 0 || smal == 0 || cif == 0) {
                char[] pasmas = pas.ToArray<char>();
                int n = pasmas.Length;
                if (big == 0 & smal == 0 & cif != 0) {
                    pasmas[0] = Convert.ToChar("A");
                    pasmas[1] = Convert.ToChar("a");
                    zam = new string(pasmas);
                }
                if (big == 0 & cif == 0 & smal != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToUpper());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal == 0 & big != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToLower());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (big == 0 & smal != 0 & cif != 0) {
                    if (smal > 1) {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToLower()))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("A");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (smal == 0 & cif != 0 & big != 0) {
                    if (big > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper()))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToLower());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("a");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal != 0 & big != 0) {
                    if (smal > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToLower()))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper()))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
            }
        }
        static void Main(string[] args)
        {
            int T = Convert.ToInt32(Console.ReadLine());
            string[] pasv = new string[T];
            for (int i = 0; i < T; i++)
            {
                pasv[i] = Console.ReadLine();
                Schet(pasv[i], out int big, out int smal, out int cif);
                Izmen(big, smal, cif, pasv[i], out string zam);
                pasv[i] = zam;
            }
            for (int i = 0; i < T; i++)
            {
                Console.WriteLine(pasv[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Schet(string a,out int big,out int smal,out int cif)
        {
            big = 0;
            smal = 0;
            cif = 0;
            foreach(char b in a)
            {
                if (char.IsUpper(b)) big += 1;
                if (char.IsLower(b)) smal += 1;
                if (char.IsDigit(b)) cif += 1;
            }
        }
        static void Izmen(int big,int smal,int cif,string pas,out string zam)
        {
            zam = pas;
            if (big == 0 || smal == 0 || cif == 0) {
                char[] pasmas = pas.ToArray<char>();
                int n = pasmas.Length;
                if (big == 0 & smal == 0 & cif != 0) {
                    pasmas[0] = Convert.ToChar("A");
                    pasmas[1] = Convert.ToChar("a");
                    zam = new string(pasmas);
                }
                if (big == 0 & cif == 0 & smal != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToUpper());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal == 0 & big != 0) {
                    pasmas[0] = Convert.ToChar(Convert.ToString(pasmas[0]).ToLower());
                    pasmas[1] = Convert.ToChar("1");
                    zam = new string(pasmas);
                }
                if (big == 0 & smal != 0 & cif != 0) {
                    if (smal > 1) {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToLower()))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("A");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (smal == 0 & cif != 0 & big != 0) {
                    if (big > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper()))
                            {
                                pasmas[i] = Convert.ToChar(Convert.ToString(pasmas[i]).ToLower());
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (Char.IsDigit(pasmas[i]))
                            {
                                pasmas[i] = Convert.ToChar("a");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
                if (cif == 0 & smal != 0 & big != 0) {
                    if (smal > 1)
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToLower()))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < n; i++)
                        {
                            if (pasmas[i] == Convert.ToChar(Convert.ToString(pasmas[i]).ToUpper()))
                            {
                                pasmas[i] = Convert.ToChar("1");
                                break;
                            }
                        }

                    }
                    zam = new string(pasmas);
                }
            }
        }
        static void Main(string[] args)
        {
            int T = Convert.ToInt32(Console.ReadLine());
            string[] pasv = new string[T];
            for(int i = 0; i < T; i++)
            {
                pasv[i] = Console.ReadLine();
                Schet(pasv[i],out int big,out int smal,out int cif);
                Izmen(big, smal, cif,pasv[i],out string zam);
                pasv[i] = zam;
            }
            for (int i = 0; i < T; i++)
            {
                Console.WriteLine(pasv[i]);
            }
            Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long T = long.Parse(Console.ReadLine());
		for(var i=0;i<T;i++){
			string str = Console.ReadLine();
			long ct1 = 0;
			long ct2 = 0;
			long ct3 = 0;
			long[] c1 = new long[str.Length];
			for(var j=0;j<str.Length;j++){
				string s1 = "abcdefghijklmnopqrstuvwxyz";
				if(s1.IndexOf(str.Substring(j,1))>=0){
					ct1 += 1;
					c1[j] = 1;
				}
				string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
				if(s2.IndexOf(str.Substring(j,1))>=0){
					ct2 += 1;
					c1[j] = 2;
				}
				string s3 = "0123456789";
				if(s3.IndexOf(str.Substring(j,1))>=0){
					ct3 += 1;
					c1[j] = 3;
				}
			}
			int[] AA = new int[3];
			AA[0] = 1;
			AA[1] = 0;
			AA[2] = 2;
			for(var k=0;k<3;k++){
			if(ct1==0){
				if(c1[AA[k]] == 2 && ct2 >= 2){
					string stra = "a";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 1;
					ct1 += 1;
					ct2 -= 1;
				}
				if(c1[AA[k]] == 3 && ct3 >= 2){
					string stra = "a";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 1;
					ct1 += 1;
					ct3 -= 1;
				}
			} else if(ct2==0){
				if(c1[AA[k]] == 1 && ct1 >= 2){
					string stra = "A";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 2;
					ct2 += 1;
					ct1 -= 1;
				}
				if(c1[AA[k]] == 3 && ct3 >= 2){
					string stra = "A";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 2;
					ct2 += 1;
					ct3 -= 1;
				}
			} else if(ct3==0){
				if(c1[AA[k]] == 1 && ct1 >= 2){
					string stra = "0";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 3;
					ct3 += 1;
					ct1 -= 1;
				}
				if(c1[AA[k]] == 2 && ct2 >= 2){
					string stra = "0";
					if(AA[k] == 0){
						str = stra + str.Substring(1,str.Length-1);
					} else if(AA[k] == 1){
						str = str.Substring(0,1) + stra + str.Substring(2,str.Length-2);
					} else if(str.Length==3){
						str = str.Substring(0,2) + stra;
					} else {
						str = str.Substring(0,2) + stra + str.Substring(3,str.Length-2);
					}
					c1[AA[k]] = 3;
					ct3 += 1;
					ct2 -= 1;
				}
			}
			}
			Console.WriteLine(str);
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces2009A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            int testCases;
            testCases = int.Parse(Console.ReadLine());

            while (testCases-- > 0)
            {
                str = Console.ReadLine();
                char[] chars = str.ToCharArray();

                List<int> digits = new List<int>();
                List<int> upper = new List<int>();
                List<int> lower = new List<int>();

                int i = 0;
                foreach (var ch in str)
                {

                    if (char.IsDigit(ch))
                        digits.Add(i);

                    else if (char.IsLower(ch))
                        lower.Add(i);

                    else if (char.IsUpper(ch))
                        upper.Add(i);

                    i++;
                }

                if (lower.Count >= 1 && upper.Count >= 1 && digits.Count >= 1)
                    Console.WriteLine(str);

                if(lower.Count == 0 && upper.Count == 0)
                {
                    chars[digits[0]] = 'a';
                    chars[digits[1]] = 'A';
                    Console.WriteLine(String.Join("",chars));
                    continue;
                }

                if (digits.Count == 0 && upper.Count == 0)
                {
                    chars[lower[0]] = '1';
                    chars[lower[1]] = 'A';
                    Console.WriteLine(String.Join("", chars));
                    continue;
                }

                if (lower.Count == 0 && digits.Count == 0)
                {
                    chars[upper[0]] = 'a';
                    chars[upper[1]] = '1';
                    Console.WriteLine(String.Join("", chars));
                    continue;
                }

                if (lower.Count == 0)
                {
                    if(upper.Count > 1)
                    {
                        chars[upper[0]] = 'a';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                    else
                    {
                        chars[digits[0]] = 'a';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                }

                if (upper.Count == 0)
                {
                    if (lower.Count > 1)
                    {
                        chars[lower[0]] = 'A';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                    else
                    {
                        chars[digits[0]] = 'A';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                }

                if (digits.Count == 0)
                {
                    if (upper.Count > 1)
                    {
                        chars[upper[0]] = '1';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                    else
                    {
                        chars[lower[0]] = '1';
                        Console.WriteLine(String.Join("", chars));
                        continue;
                    }
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;

class Solver
{
    public Scanner sc;
    public void Solve()
    {
        var T = sc.Int;
        int f(char c)
        {
            if ('0' <= c && c <= '9') return 0;
            if ('a' <= c && c <= 'z') return 1;
            return 2;
        }
        while (T-- > 0)
        {
            var S = sc.Str.ToCharArray();
            var use = new bool[3];
            use[f(S[0])] = true;
            int r;
            for (r = S.Length - 1; r >= 0; r--)
            {
                if (!use[f(S[r])])
                {
                    use[f(S[r])] = true;
                    break;
                }
            }
            var C = new[] { '0', 'a', 'A' };
            if (r == -1)
            {
                int idx = 1;
                for (int i = 0; i < 3; i++)
                {
                    if (!use[i]) { S[idx++] = C[i]; }
                }
                Console.WriteLine(new string(S)); continue;
            }
            for (int i = 1; i < r; i++)
                if (!use[f(S[i])])
                {
                    Console.WriteLine(new string(S)); goto EBD;
                }
            for (int i = 0; i < 3; i++)
            {
                if (!use[i]) { S[1] = C[i]; }
            }
            Console.WriteLine(new string(S));
        EBD:;
        }
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var sol = new Solver() { sc = new Scanner() };
        //var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
        sol.Solve();
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static void Out<T>(this IList<T> A, out T a) => a = A[0];
    public static void Out<T>(this IList<T> A, out T a, out T b) { a = A[0]; b = A[1]; }
    public static void Out<T>(this IList<T> A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; }
    public static void Out<T>(this IList<T> A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; }
    public static string Concat<T>(this IEnumerable<T> A, string sp) => string.Join(sp, A);
    public static char ToChar(this int s, char begin = '0') => (char)(s + begin);
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}

#endregion