#pragma GCC optimize("O3")
#pragma GCC target("popcnt,lzcnt,bmi,bmi2,abm")
#include <iostream>
#include <vector>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
// #include <limits.h>
// #include<bits/stdc++.h>
using namespace std;
// template < typename A, typename B > ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
// template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// void dbg_out() { cerr << '\n'; }
// template<typename Head, typename... Tail>
// void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
// #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#define PI 3.141592653589793116
// PI = acos(-1)
#define ll long long
#define ld long double
#define fi first
#define se second
#define nl '\n'
#define all(x) x.begin(), x.end()
#define no cout << "NO" << nl
#define yes cout << "YES" << nl
#define siu ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(x,y) memset(x,y,sizeof(x));
#define pb push_back
const ll mod = 1e9 + 7;
const int inf = 1e9;
const int lim = 1e6 + 5;
const int base = 311;
const ll gh = 1005;
void file()
{
siu
// #ifdef ONLINE_JUDGE
// freopen("tongnn.INP","r",STdin);
// freopen("tongnn.OUT","w",STdout);
// #endif // ONLINE_JUDGE
#ifndef ONLINE_JUDGE
freopen("ahihi.INP","r",stdin);
freopen("ahihi.OUT","w",stdout);
#endif // ONLINE_JUDGE
}
ll n,m,i,j,k,t,kq=0;
ll x,y,z,maxa=-1e9,mina=1e9,l=1,r=1e9;
ll a[lim],f[lim];
void solve()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
a[i]%=5;
if(a[i]==0) a[i]=5;
f[a[i]]++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