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

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

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

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

e = A("e")
j = B("j")
a = C("a")
h = D("h")
c = B("c")

e.q = a
e.p = a
e.u = j
j.u = e
j.w = e
j.q = a
a.z = c
h.w = a
c.u = e
c.w = e
c.q = a
assert e.q.z.q.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.u: B = None
        self.p: C = None
        self.txt = txt

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

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

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

e = A("e")
j = B("j")
a = C("a")
h = D("h")
c = B("c")

e.q = a
e.p = a
e.u = j
j.u = e
j.w = e
j.q = a
a.z = c
h.w = a
c.u = e
c.w = e
c.q = a
assert e.q.z.q.z.u.txt == "e"