Given two nonempty arrays of natural numbers \$a\$ and \$b\$, return the shortest nonempty array of pairs of natural numbers \$q\$ such that the sequence of first elements of \$q\$ consists of a whole number of repeated copies of \$a\$, and the sequence of second elements of \$q\$ consists of a whole number of repeated copies of \$b\$.
When \$a\$ and \$b\$ have the same length, this acts like a zip, but when the lengths of \$a\$ and \$b\$ are coprime, this acts like a Cartesian product.
You can use any reasonable input and output format for arrays (pointers, lists, space-separated strings, strings of char codes, etc.)
This is code-golf, so the shortest valid answer (measured in bytes) wins.
Test Cases
[1], [2] -> [(1, 2)]
[1, 2], [3] -> [(1, 3), (2, 3)]
[1, 2], [3, 4] -> [(1, 3), (2, 4)]
[1, 2, 3, 4], [5, 6] -> [(1, 5), (2, 6), (3, 5), (4, 6)]
[5, 5, 5], [5, 5, 5] -> [(5, 5), (5, 5), (5, 5)]
[5, 5], [5, 5, 5] -> [(5, 5), (5, 5), (5, 5), (5, 5), (5, 5), (5, 5)]
[1, 2, 3, 4], [1, 2, 3, 4, 5, 6] ->
[(1, 1), (2, 2), (3, 3), (4, 4),
(1, 5), (2, 6), (3, 1), (4, 2),
(1, 3), (2, 4), (3, 5), (4, 6)]