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

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

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

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

j = A("j")
h = B("h")
k = C("k")
b = D("b")
c = D("c")

j.z = h
j.t = c
j.r = c
h.o = k
h.p = j
k.r = h
k.q = h
b.q = c
b.z = k
c.q = b
c.z = k
assert h.p.t.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.t: D = None
        self.r: D = None
        self.txt = txt

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

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

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

j = A("j")
h = B("h")
k = C("k")
b = D("b")
c = D("c")

j.z = h
j.t = c
j.r = c
h.o = k
h.p = j
k.r = h
k.q = h
b.q = c
b.z = k
c.q = b
c.z = k
assert h.p.t.z.q.txt == "h"