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

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

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

h = A("h")
f = B("f")
j = C("j")
e = B("e")
i = B("i")
l = C("l")
d = C("d")

h.x = i
h.y = l
h.w = l
f.q = l
f.r = e
j.z = h
e.q = l
e.r = i
i.q = d
i.r = f
l.z = h
d.z = h
assert d.z.x.r.r.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: C = None
        self.w: C = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
j = C("j")
e = B("e")
i = B("i")
l = C("l")
d = C("d")

h.x = i
h.y = l
h.w = l
f.q = l
f.r = e
j.z = h
e.q = l
e.r = i
i.q = d
i.r = f
l.z = h
d.z = h
assert d.z.x.r.r.q.z.txt == "h"