import std.stdio;
struct A{int x;}
struct B{C y;}
struct C{int z;}
int func(T)(T t){
static if(is(T:A)){
return t.x;
}else static if(is(T:B)){
return func(t.y);
}else static if(is(T:C)){
return t.z;
}
}
void main()
{
writeln(func(*new A));
writeln(func(*new B));
writeln(func(*new C));
}
aW1wb3J0IHN0ZC5zdGRpbzsKCnN0cnVjdCBBe2ludCB4O30Kc3RydWN0IEJ7QyB5O30Kc3RydWN0IEN7aW50IHo7fQoKaW50IGZ1bmMoVCkoVCB0KXsKCXN0YXRpYyBpZihpcyhUOkEpKXsKCQlyZXR1cm4gdC54OwoJfWVsc2Ugc3RhdGljIGlmKGlzKFQ6QikpewoJCXJldHVybiBmdW5jKHQueSk7Cgl9ZWxzZSBzdGF0aWMgaWYoaXMoVDpDKSl7CgkJcmV0dXJuIHQuejsKCX0KfQoKdm9pZCBtYWluKCkKewoJd3JpdGVsbihmdW5jKCpuZXcgQSkpOwoJd3JpdGVsbihmdW5jKCpuZXcgQikpOwoJd3JpdGVsbihmdW5jKCpuZXcgQykpOwp9