Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 1059/C. Beautiful XOR
PrevNext
CodeforcesCodeforces
Specialist
Codeforces Round 1059

C. Beautiful XOR

Bit ManipulationBitmaskGreedyArray
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

You are given two integers π‘Ž

 and π‘

. You are allowed to perform the following operation any number of times (including zero):

  • choose any integer π‘₯
  •  such that 0≀π‘₯β‰€π‘Ž
  •  (the current value of π‘Ž
  • , not initial),
  • set π‘Ž:=π‘ŽβŠ•π‘₯
  • . Here, βŠ•
  •  represents the bitwise XOR operator.

After performing a sequence of operations, you want the value of π‘Ž

 to become exactly π‘

.

Find a sequence of at most 100

 operations (values of π‘₯

 used in each operation) that transforms π‘Ž

 into π‘

, or report that it is impossible.

Note that you are not required to find the minimum number of operations, but any valid sequence of at most 100

 operations.

Input


The first line of input contains a single integer π‘‘

 (1≀𝑑≀1000

) β€” the number of test cases.

Each test case contains two integers π‘Ž

 and π‘

 (1β‰€π‘Ž,𝑏≀10

9

).

Output


For each test case, if it is impossible to obtain π‘

 from π‘Ž

 using the allowed operations, print a single line containing βˆ’1

.

Otherwise, on the first line print a single integer π‘˜

 (0β‰€π‘˜β‰€100

) β€” the number of operations. On the second line print π‘˜

 integers (π‘₯

1

,π‘₯

2

,…,π‘₯

π‘˜

) β€” the chosen values of π‘₯

 in the order you apply them.

If there are multiple valid sequences, you may print any one of them.

Example

Input

Copy

6
9 6
13 13
292 929
405 400
998 244
244 353

Output

Copy

2
7 8
0
-1
1
5
2
25 779
-1

Note


For the first test case,

  • choose π‘₯=7
  • , now π‘Ž
  •  becomes equal to 9βŠ•7=14
  • .
  • choose π‘₯=8
  • , now π‘Ž
  •  becomes equal to 14βŠ•8=6
  • .

Thus, we can make π‘Ž=𝑏

.

For the fourth test case, choosing π‘₯=5

 makes π‘Ž=𝑏

.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 1059
Previous ProblemNext Problem