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

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

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

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

i = A("i")
n = B("n")
a = C("a")
j = D("j")
m = C("m")
l = A("l")

i.q = l
n.p = l
n.y = m
a.w = j
a.z = m
a.p = i
j.x = a
j.q = n
j.z = n
j.s = m
m.w = j
m.z = a
m.p = i
l.q = i
assert a.p.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

i = A("i")
n = B("n")
a = C("a")
j = D("j")
m = C("m")
l = A("l")

i.q = l
n.p = l
n.y = m
a.w = j
a.z = m
a.p = i
j.x = a
j.q = n
j.z = n
j.s = m
m.w = j
m.z = a
m.p = i
l.q = i
assert a.p.q.q.q.q.txt == "i"