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

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

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

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

h = A("h")
g = B("g")
e = C("e")
i = D("i")

h.p = g
h.q = e
h.y = e
g.u = i
e.v = h
e.p = i
i.z = h
i.o = h
assert i.z.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: C = None
        self.y: C = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
e = C("e")
i = D("i")

h.p = g
h.q = e
h.y = e
g.u = i
e.v = h
e.p = i
i.z = h
i.o = h
assert i.z.p.u.txt == "i"