A. Blackslex and Password

time limit per test

1 second

memory limit per test

256 megabytes

Blackslex is designing a log-in system for Gean Dev and discovered that most users use weak passwords.

To resolve this issue, he posed the following conditions, dependent on two variables k and x, for all passwords. Each password is a string s of length n satisfying these properties.

  • s uses only the first k lowercase letters of the English alphabet.
  • For every pair of indices 1≤i<j≤n such that (j−i) is divisible by x, the letters si and sj are different.

Find the smallest integer n such that no valid string of length n exists.

Input

The first line contains a single integer t (1≤t≤500) --- the number of test cases.

The first and only line of each test case contains two integers k and x (1≤k≤26, 1≤x≤15).

Output

For each test case, output the minimal n.

Example

Input

Copy

复制代码

3

2 1

3 2

1 5

Output

Copy

复制代码

3

7

6

Note

For the first test case, there are no valid strings of length n=3. For n=2, one such valid example is ab. Note that the only pair (i,j) that (j−i) is divisible by x=1 and 1≤i<j≤n for n=2 is (1,2).

For the second test case, there are no valid strings of length n=7. For n=6, one such valid example is aabccb. Note that all pairs (i,j) that (j−i) is divisible by x=2 and 1≤i<j≤n for n=6 include (1,3), (1,5), (2,4), (2,6), (3,5), and (4,6).

For the third test case, there are no valid strings of length n=6. For n=5, one such valid example is aaaaa. Note that there are no pairs (i,j) that (j−i) is divisible by x=5 and 1≤i<j≤n for n=5.

解题说明:此题是一道数学题,找规律能发现输出k*x+1。求出来满足有效字符串的最大的n,将其+1即可,让每个字符连续出现x次,答案即为k*x+1。

cpp 复制代码
#include<stdio.h>
int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		int k, x;
		scanf("%d %d", &k, &x);
		printf("%d\n", 1 + k * x);
	}
	return 0;
}
相关推荐
天空'之城3 小时前
C 语言工业级通用组件手写 08:精准软件消抖
c语言·嵌入式开发·工业级组件·软件消抖·按键防抖
Legendary_0085 小时前
LDR6500 设计指南:Type-C 音频快充二合一配件 PD 取电与插拔时序控制方案
c语言·开发语言·音视频
会飞的小新6 小时前
C 标准库之 <fenv.h> 详解与深度解析
c语言·开发语言·microsoft
爱刷碗的苏泓舒7 小时前
C 语言 if-else 与 switch-case 分支语句对比
c语言·开发语言
无相求码7 小时前
指针的5层境界,从入门到劝退:C语言指针进阶全解析
c语言
C++ 老炮儿的技术栈8 小时前
基于MFC+原生GDI手动自绘仪表盘控件
c语言·c++·visual studio·控件·工业控制·gdi·自绘
小肝一下8 小时前
3. 单链表
c语言·数据结构·c++·算法·leetcode·链表·dijkstra
炸膛坦客17 小时前
单片机/C/C++八股:(二十六)IIC 专题(I²C)---- 上集
c语言·c++·单片机
程序员Rock1 天前
上位机开发-MODBUS面试常见问题
c语言·c++·面试·职场和发展·上位机
blevoice1 天前
抖抖燃脂机单 AC6966B 主控调试踩坑:Type-C 整机供电喇叭无声排障
c语言·开发语言·单片机