Merging Digital River
Your code is disappointing.... as C++. Really, it is a C program written in C++. There's no classes, objects, instances, etc. In part, this is one of the reasons your code is slow.

A natural consequence of the way you compute your answers is that you have to re-build the entire stream 1, 3, and 9 sequences each time the code encounters a new test. If you had a "stream" class for each of the three base classes, and you "remembered" the stream, and made it searchable, then you would have a way to look up whether a test stream value joins. Using an iterator would make sense for the process too.

Iterate the stream, find if there is an intersection, move on.

your code is actually far worse than I realized when it comes to calculating the base 1,3, and 9 streams.... it rebuilds each stream each time you test a new value, for each new value in each test case... thus, for example, you could be computing millions, and millions of values unnecessarily.

You need to "remember" and "index" the base streams, and you'll fare much better.

Also, use the language to your advantage: classes, iterators, vectors, etc.