"use strict";
var global_context = global ? global : window;

(function DefineUnderScore() {
    var ArrayProto = Array.prototype;
    var slice = ArrayProto.slice;
    this._ = {};
    _.each = function( obj, iterator, context ) {
        Object.keys(obj).forEach(function(key) {
            if ( iterator.call( context, obj[key], key, obj ) === true )
                return true;
        });
    };
    _.extend = function(obj) {
        _.each(slice.call(arguments, 1), function(source) {
            Object.keys(source).forEach(function(key) {
                obj[key] = source[key];
            });
        });
    };
}).call(global_context);

function Deferred() {
    var queue = [];
    var obj = {
        done: function(func, context) {
            if ( func instanceof Function )
                queue.push({
                    callback: func,
                    context: context
                });
            return this;
        },
        call: function() {
            var args = arguments;
            setTimeout(function() {
                queue.forEach(function(obj) {
                    obj.callback.apply(obj.context, args);
                });
            }, 0);
        }
    };
    return obj;
}

function RawInput() {
    var deferred = new Deferred();
    var stdin = process.stdin;
    stdin.resume();
    stdin.setEncoding('ascii');
    var buffer = '';
    stdin.on('data', function(chunk) {
        buffer += chunk.toString();
    });
    stdin.on('end', function() {
        deferred.call(buffer);
    });
    return deferred;
}

(function DefineSolution( namespace ) {
    var Solution = function() {
        this.input_list = [];
    };
    Solution.prototype = {
        input: function() {
            if ( this.separator instanceof Function )
                this.input_list = this.separator.call( this, this.raw_data );
            else
                this.input_list.push(this.raw_data);
        },
        run: function(raw_data) {
            this.raw_data = raw_data;
            this.input();
            while ( this.has_next() )
                this.solve(this.next()).output();
        },
        read_line: function() {
            return this.input_list.splice(0,1)[0];
        },
        check_eof: function() {
            return ! this.input_list.length;
        },
        has_next: function() {
            return ! this.check_eof();
        }
    };
    this[namespace] = Solution;
}).call(global_context, 'Solution' );

(function ExtendSolution( namespace ) {
    var YES = 'Yes';
    var NO = 'No';

    var G = {
        A: { 0: 'X', 1: 'Y' },
        X: { 0: undefined, 1: 'Z' },
        Z: { 0: 'W', 1: 'B' },
        W: { 0: 'B', 1: 'Y' },
        Y: { 0: 'X', 1: undefined },
        B: { 0: 'Y', 1: 'X' },
        undefined: { 0: undefined, 1: undefined }
    };

    _.extend(Solution.prototype, {
        separator: function(data) {
            var res = data.split('\n');
            return res;
        },
        check_eof: function() {
            return this.input_list[0] === '#';
        },
        next: function() {
            return {
                s: this.read_line()
            };
        },
        solve: function(options) {
            var s = options.s;
            var current = 'A';
            s.split('').forEach(function(dir) {
                current = G[current][dir];
            });
            this.result = current === 'B';
            return this;
        },
        output: function() {
            console.log( this.result ? YES : NO );
        }
    });
})();

var solution = new Solution;
RawInput.call(global_context).done(solution.run, solution);

Measured memory_bytes: 8408