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

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

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

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

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

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

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

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

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

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

j.z = m
j.r = h
m.o = e
m.y = b
m.z = j
b.x = j
b.q = h
h.s = b
h.t = b
e.s = b
e.t = b
assert b.q.t.x.r.s.txt == "b"