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

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

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

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

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

d.p = a
j.o = i
k.s = a
k.t = d
m.w = c
m.z = k
m.q = a
i.o = j
c.w = m
c.z = k
c.q = d
a.p = d
assert a.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

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

d.p = a
j.o = i
k.s = a
k.t = d
m.w = c
m.z = k
m.q = a
i.o = j
c.w = m
c.z = k
c.q = d
a.p = d
assert a.p.p.p.txt == "d"