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

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

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

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

f = A("f")
i = B("i")
l = C("l")
h = D("h")
g = A("g")

f.p = i
i.z = h
l.q = i
l.w = i
l.u = g
l.s = g
h.o = l
h.z = f
g.p = i
assert h.z.p.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

f = A("f")
i = B("i")
l = C("l")
h = D("h")
g = A("g")

f.p = i
i.z = h
l.q = i
l.w = i
l.u = g
l.s = g
h.o = l
h.z = f
g.p = i
assert h.z.p.z.o.txt == "l"