#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;

int32_t main()
{
    int t = 1;
    cin>>t;
    while(t--)
    {
        int k, n, m;
        cin>>n;

        vector <int> A(n), B(n, 0);
        for( int i = 0; i < n; i++ ) cin>>A[i];

        for( int i = 1; i < n; i++ )
        {
            int last = ( B[i-1]^A[i-1] );
            for( int j = 0; j <= 30; j++ )
            {
                int num = 1 << j;
                if( last & num )
                {
                    if( ( A[i] & num )== 0 )
                        B[i] ^= num;
                }
            }
        }

        for( auto v: B )
            cout<<v<<" ";
        cout<<"\n";
    }

    return 0;
}