Comparing Version Strings

easy strings parsing 1000 ms · 256 MB

Comparing Version Strings

Your team's deployment tool refuses to roll out a build unless it is newer than the one already running. Release versions are written as dotted strings like 1.02.10 or 2.0.0.7, but they come from many different build pipelines, and those pipelines disagree about formatting: some pad components with leading zeros, some drop trailing .0 parts, and one nightly pipeline stamps a full timestamp-plus-hash number into a single component, up to 50 digits long.

Versions are compared as follows:

  • A version is a sequence of components, separated by dots. Each component is a non-negative integer written in decimal, possibly with leading zeros, so 01, 001 and 1 all mean the same number, and 000 means 0.
  • If one version has fewer components than the other, it is extended with components equal to 0 until both have the same count. So 1.2, 1.2.0 and 1.02.0.00 are all equal.
  • The versions are then compared component by component from left to right. The first position where the numbers differ decides: the version with the smaller number there is older. If no position differs, the versions are equal.

You are given q pairs of versions. For each pair, report how the first version relates to the second.

Input

The first line contains an integer q (1 ≤ q ≤ 10^5), the number of pairs.

Each of the next q lines contains two version strings a and b, separated by a single space.

Every version string consists of one or more components separated by single dots. Every component is a non-empty string of between 1 and 50 decimal digits (0–9). There are no other characters: no leading or trailing dots, no two consecutive dots, no signs. Each version string has length at most 200, and the total length of all 2q version strings is at most 4·10^6.

Output

Print q lines. On the i-th line print older if the first version of the i-th pair is older than the second, newer if it is newer, and equal if the two versions are equal.

Notes

In the first example:

  • 1.02.10 vs 1.2.9.0: the first components are both 1, the second are both 2, and in the third 10 > 9, so the first version is newer.
  • 1.0 vs 1.0.0.0: the missing components count as 0, so the versions are equal.
  • 0.9 vs 0.10: 9 < 10 as numbers, so the first version is older, even though the string 9 sorts after 10 alphabetically.
  • 3 vs 3.0.1: the first version is extended to 3.0.0, and 0 < 1 in the last component.

A component may have up to 50 digits, which does not fit in a 64-bit integer.

Example 1

Input

4
1.02.10 1.2.9.0
1.0 1.0.0.0
0.9 0.10
3 3.0.1

Output

newer
equal
older
older

Example 2

Input

6
000.0 0
12345678901234567890123 12345678901234567890124
2.000000000000000000001 2.1
10.0.0.1 9.99.99
1.0.0.0.0.0.0.0.2 1.0.0.0.0.0.0.0.10
7.18446744073709551616 7.0

Output

equal
older
equal
newer
older
newer

Hints · reveal one at a time if you're stuck

Hint 1

Some components have up to 50 digits, so they do not fit in a 64-bit integer. Can you decide which of two digit strings is larger without converting them to numbers?

Hint 2

Treat missing trailing components as zeros, and ignore leading zeros when comparing. Then compare the significant digits of each component by length first, and by the digits themselves when the lengths match.

report an issue Prefer your own editor? sooks prep 30 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.