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

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

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

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

i = A("i")
a = B("a")
n = C("n")
d = D("d")
h = B("h")

i.t = a
i.q = a
i.p = d
a.y = i
a.z = d
n.u = d
d.r = i
d.u = h
d.w = a
d.o = n
h.y = i
h.z = d
assert a.y.p.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.p: D = None
        self.txt = txt

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

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

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

i = A("i")
a = B("a")
n = C("n")
d = D("d")
h = B("h")

i.t = a
i.q = a
i.p = d
a.y = i
a.z = d
n.u = d
d.r = i
d.u = h
d.w = a
d.o = n
h.y = i
h.z = d
assert a.y.p.o.u.txt == "d"