#!/usr/bin/env python3 import math from typing import * def solve(a: int, b: int) -> List[int]: if a == b: return [] c = [] e = [] if a % 2 == 1: a += 1 c.append(1) if b % 2 == 1: b -= 1 e.append(1) d = math.gcd(a, b) a //= d b //= d return c + [d * x for x in solve(a, b)] + e # generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) def main(): t = int(input()) for i in range(t): a, b = map(int, input().split()) c = solve(a, b) print(len(c)) print(*c) if __name__ == '__main__': main()