#include <iostream>
using namespace std;

int a[510];
int n;

void func() {
    for (int i = 0; i < n; i++) {
        int t = a[i];
        while (t != 1) {
            if (t % 2 == 0) {
                t /= 2;
                for (int j = 0; j < n; j++) {
                    if (a[j] == t) a[j] = 1; //覆盖数置为1
                }
            }else{
                t=3*t+1;
                t/=2;
                for(int j=0;j<n;j++){
                    if(a[j]==t) a[j]=1;
                }
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        if(a[i]!=1) cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    while (cin >> n && n) {
        for (int i = 0; i < n; i++) cin >> a[i];
        func();
    }
    return 0;
}