Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to find out someone has changed the volume to aa. Of course, Bob has a remote control that can change the volume.

There are six buttons (−5,−2,−1,+1,+2,+5−5,−2,−1,+1,+2,+5) on the control, which in one press can either increase or decrease the current volume by 11, 22, or 55. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than 00.

As Bob is so angry, he wants to change the volume to bb using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given aa and bb, finds the minimum number of presses to change the TV volume from aa to bb.

Input

Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤10001≤T≤1000). Then the descriptions of the test cases follow.

Each test case consists of one line containing two integers aa and bb (0≤a,b≤1090≤a,b≤109) — the current volume and Bob's desired volume, respectively.

Output

For each test case, output a single integer — the minimum number of presses to change the TV volume from aa to bb. If Bob does not need to change the volume (i.e. a=ba=b), then print 00.

Example

Input

3
4 0
5 14
3 9

Output

2
3
2

Note

In the first example, Bob can press the −2−2 button twice to reach 00. Note that Bob can not press −5−5 when the volume is 44 since it will make the volume negative.

In the second example, one of the optimal ways for Bob is to press the +5+5 twice, then press −1−1 once.

In the last example, Bob can press the +5+5 once, then press +1+1.

能选5的时候选5,不能选5的时候选2,不能选2的时候选1。

验证可行性,如果有个大于等于5的数,不选5那么至少要选两个2一个1,甚至更多,所以直接贪心,完事。

#include<bits/stdc++.h>
#define MAXM 100000000
#define MAXN 1000005
using namespace std;
int main()
{
int a,b,t;
cin>>t;
while(t--)
{ cin>>a>>b;
int ans=abs(a-b);
int c=ans%5;
int sum=(ans-c)/5;
ans=c%2;
sum+=(c-ans)/2+ans;
cout<<sum<<endl;
}
}

Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)的更多相关文章

  1. Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)

    Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he deci ...

  2. Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)

    Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...

  3. Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)

    Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...

  4. Codeforces Round #601 (Div. 2) A Changing Volume

    好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...

  5. 【cf比赛记录】Codeforces Round #601 (Div. 2)

    Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...

  6. Codeforces Round #601 (Div. 2)

    传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...

  7. codeforce Codeforces Round #201 (Div. 2)

    cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...

  8. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

随机推荐

  1. 安卓开发学习日记 DAY5——监听事件onClick的实现方法

    今天主要学习了监听事件的是实现方法,就是说,做了某些动作后,怎么监听这个动作并作出相应反应. 方法主要有三种: 1.匿名内部类的方法 2.独立类的方法 3.类似实现接口的方法 以下分别分析: 1.匿名 ...

  2. jvm入门及理解(四)——运行时数据区(堆+方法区)

    一.堆 定义: Heap,通过new关键字创建的对象,都存放在堆内存中. 特点 线程共享,堆中的对象都存在线程安全的问题 垃圾回收,垃圾回收机制重点区域. jvm内存的划分: JVM内存划分为堆内存和 ...

  3. CentOS安装C函数库的man帮助

    安装linux可能没有安装C的man帮助, 像我安装时选择的是最小化安装就没有, 网上的大多是ubunu的安装方式,或者是C++的man帮助, 都不适合,那么CentOS安装C man手册的方法就是: ...

  4. 360众测考试,weblogic题(CVE-2018-2894)文件上传漏洞

    0x01 漏洞简介 Weblogic管理端未授权的两个页面存在任意上传jsp文件漏洞,进而获取服务器权限. Oracle 7月更新中,修复了Weblogic Web Service Test Page ...

  5. cxGrid增加一栏显示checkBox的设置方法

    鉴于本人首次设定cxGrid的CheckBox的时候费了很大劲,发现很多人都会碰到这个问题,现在总结一下,以供各位互相学习借鉴. 步骤如下(不分先后): 1. cxGrid添加完自己所需的所有字段后, ...

  6. Java Instrumentation插桩技术学习

    Instrumentation基础 openrasp中用到了Instrumentation技术,它的最大作用,就是类的动态改变和操作. 使用Instrumentation实际上也可以可以开发一个代理来 ...

  7. 机器学习常见面试题—支持向量机SVM

    前言 总结了2017年找实习时,在头条.腾讯.小米.搜狐.阿里等公司常见的机器学习面试题. 支持向量机SVM 关于min和max交换位置满足的 d* <= p* 的条件并不是KKT条件 Ans: ...

  8. Linux学习笔记(八)权限管理命令

    权限管理命令 权限位含义 chmod chown chgrp umask默认权限 权限位含义 第1位代表文件类型 "-":普通文件 "b":块设备文件 &quo ...

  9. mongo基础

    以下如有任何问题,直接到官方操作文档左上角搜索框搜索 安装 On Windows, this path is on the drive from which you start MongoDB. Fo ...

  10. [PHP] 生成二维码(两种方法)

    方法一:(调用google二维码接口,本人测试网不好,不好用!) <?php //1.封装生成二维码图片的函数(方法) /** *利用google api生成二维码图片 * $content:二 ...