Under construction

Still being built. Things may change

Round-Robin League

Time limit2sMemory limit1024 MB

Summary
Given points for a win, draw, and loss, find the maximum and minimum points the kth-ranked team can finish with in an n-team round-robin.
Level

Medium7 of 10

Topics
Math, Greedy, Implementation
Solved
No attempts yet

Problem

In a round-robin league, teams 1 through nn play each other exactly once. Each match ends in a win, a loss, or a draw. A win earns aa points, a draw earns bb points, and a loss earns cc points. Unlike the usual scoring in round-robin leagues, the relative order of aa, bb, and cc is not fixed in this problem. For example, a win may earn fewer points than a loss.

Teams are ranked by points, highest first. If two teams have the same points, the team with the smaller number ranks higher. After all matches end, find the maximum and minimum points that the team ranked kkth can have.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains aa, bb, cc, nn, and kk, separated by spaces.

Output

For each test case, print on one line the maximum and minimum points that the team ranked kkth can have, in that order.

Constraints

  • 1≤T≤100 0001 \le T \le 100\,000
  • 0≤a,b,c≤1090 \le a, b, c \le 10^9
  • 1≤k≤n≤1091 \le k \le n \le 10^9

Hint

Examples1

  1. Example 1

    Input
    5
    3 1 0 4 1
    3 1 0 4 2
    7 7 7 7 3
    4 7 8 6 4
    2 0 5 5 2
    
    Expected output
    9 3
    7 2
    42 42
    37 24
    17 0