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) C. League of Leesins (大模拟)

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

  2. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) 思维 + 质因子

    传送门 文章目录 题意: 思路: 题意: 大体题意跟easyeasyeasy版本差不多,就是hardhardhard版本的aaa范围更大.见这里Codeforces Round #601 (Div. ...

  3. Codeforces Round #601 (Div. 2)

    传送门 文章目录 A.Changing Volume 题意: 思路: B. Fridge Lockers 题意: 思路: C. League of Leesins 题意: 思路: D. Feeding ...

  4. Codeforces Round #433(Div. 2) D. Jury Meeting(贪心)

    题目链接:Codeforces Round #433(Div. 2) D. Jury Meeting 题意: 有n个城市,每个城市有一个人,现在要让这些人来0号城市在一起k天,然后回去. 现在有m个日 ...

  5. Codeforces Round #656 (Div. 3) F. Removing Leaves 贪心 + 模拟

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个贪心策略就是每次都找一个叶子节点最多的点,让后删掉他的kkk个叶子节点,现在我们就来考虑如何模拟这个过程. 我们整一个vector<s ...

  6. Codeforces Round #601 (Div. 2)D. Feeding Chicken,二维压一维,几何平面的分配

    D. Feeding Chicken 题目大意:就是给你一个r∗cr*cr∗c的矩阵,矩阵上若干个位置上有食物,你有k只小鸡,你要将这r∗cr*cr∗c的矩阵分成k个联通块给每个小鸡,使得有最大食物的 ...

  7. Codeforces Round #601 (Div. 2)B. Fridge Lockers

    B. Fridge Lockers [题目类型]模拟 [题目链接]B题链接 [题目大意]给你n个冰箱,m个铁链对这n个冰箱连接,要求使用所有的铁链对冰箱进行连接,满足非冰箱主人不能独自打开,u冰箱连接 ...

  8. Codeforces Beta Round #52 (Div. 2) D. Changing a String DP输出方案

    https://codeforces.com/contest/56/problem/D 就是编辑距离的加强版,需要输出方案,那么状态转移方程应该比较常规了,设 d p [ i ] [ j ] dp[i ...

  9. Codeforces Round #180 (Div. 2) A. Snow Footprints 贪心

    A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a stra ...

最新文章

  1. python的dict实现
  2. DataV 支持 token 验证啦!
  3. Qt 2D painting Demo 的翻译
  4. 软件工程模块开发卷宗_软件智能化再进一步,未来人人都能开发软件?
  5. 保存的图数据丢失_自从用了这2个功能,再也没有担心过文档丢失
  6. upload Fiori application to ABAP server via report /UI5/UI5_REPOSITORY_LOAD
  7. 没有完美的软件:编程永远不容易
  8. sqlserver 插入数据时异常,仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'XXXXX.dbo.XXXXXXXXX'中的标识列指定显式值。...
  9. Ubuntu 安装 Redis
  10. linux非root用户搭建docker,linux centos7 非root用户安装源码版docker
  11. 搜索关键字高亮显示,就比微信多个多音字搜索
  12. JavaScript数据类型之Number
  13. 手机网站如何制作,移动网站怎么建设?
  14. 计算机如何用vb文本加密,怎么样用VB编写一个文件加密程序
  15. PageRank 计算博客园用户排名
  16. Spring Boot3.0正式发布及新特性解读
  17. 介绍理想工作计算机 英语作文,我的理想工作(My Ideal Job)
  18. 设定是否使用IOB中的寄存器
  19. LayaBox ARPG游戏副本之《帮派联赛》水晶占领核心玩法详解
  20. ps修改图片中的图片尺寸

热门文章

  1. Android中TextView中string的特殊符号显示的方法
  2. java给定任意_java生成任意整数随机数(任意指定范围)
  3. php mysql query 创建_借助PHP的mysql_query()函数来创建MySQL数据库的教程_MySQL
  4. fastxml 大于符号不转换_你可能不知道的MATLAB入门技巧#第二话
  5. ios8 定位问题解决思路
  6. Android中的JSON解析方式:json; Gson ; Fastjson
  7. layoutSubviews什么时候触发调用
  8. 在linux操作系统中启动oracle数据库程序,Linux系统下Oracle数据库的安装和启动关闭操作教程...
  9. React性能优化:immutability-helper
  10. Mysql 中的事件//定时任务