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

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

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

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

a = A("a")
l = B("l")
c = C("c")
i = D("i")
h = A("h")

a.p = h
a.r = i
l.r = i
c.u = l
c.p = h
c.q = a
c.y = i
i.z = c
h.p = a
h.r = i
assert l.r.z.u.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: D = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
c = C("c")
i = D("i")
h = A("h")

a.p = h
a.r = i
l.r = i
c.u = l
c.p = h
c.q = a
c.y = i
i.z = c
h.p = a
h.r = i
assert l.r.z.u.r.z.txt == "c"