class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.t: D = None
        self.x: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: D = None
        self.r: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.r: D = None
        self.z: A = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

m = A("m")
f = B("f")
b = C("b")
h = D("h")
e = B("e")

m.y = h
m.t = h
m.x = b
f.o = h
f.r = b
b.t = m
b.x = m
b.z = m
b.r = h
h.z = e
e.o = h
e.r = b
assert m.x.x.y.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.t: D = None
        self.x: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: D = None
        self.r: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.r: D = None
        self.z: A = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

m = A("m")
f = B("f")
b = C("b")
h = D("h")
e = B("e")

m.y = h
m.t = h
m.x = b
f.o = h
f.r = b
b.t = m
b.x = m
b.z = m
b.r = h
h.z = e
e.o = h
e.r = b
assert m.x.x.y.z.r.txt == "b"