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

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

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

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

j = A("j")
k = B("k")
d = C("d")
m = D("m")

j.q = d
j.o = k
j.z = k
k.s = d
d.t = m
d.x = j
d.y = j
d.r = k
m.o = j
m.p = d
assert k.s.t.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.o: B = None
        self.z: B = None
        self.txt = txt

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

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

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

j = A("j")
k = B("k")
d = C("d")
m = D("m")

j.q = d
j.o = k
j.z = k
k.s = d
d.t = m
d.x = j
d.y = j
d.r = k
m.o = j
m.p = d
assert k.s.t.p.r.txt == "k"