#include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define pb push_back #define mkp make_pair #define fi first #define se second #define FOR(i, l, r) for(int i = l; i <= r; i++) #define ROF(i, r, l) for(int i = r; i >= l; i--) #define all(a) a.begin(), a.end() inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; } inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; } #define clean(a) memset(a, 0, sizeof(a)) int n, m, T; int main(){ #ifndef ONLINE_JUDGE freopen("x.in", "r", stdin); freopen("x.out", "w", stdout); #endif scanf("%d", &T); while(T--){ scanf("%d%d", &n, &m); int cnt = 0, i = 0; while(n){ if(n & 1){ if(i <= m) cnt++; else cnt += 1 << (i - m); }i++; n /= 2; } printf("%d\n", cnt); } return 0; } /* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */