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

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

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

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

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

a.s = l
a.q = i
f.s = h
h.p = l
h.q = l
h.u = i
l.u = a
i.p = l
i.q = l
i.u = h
assert a.s.u.q.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.q: C = None
        self.txt = txt

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

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

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

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

a.s = l
a.q = i
f.s = h
h.p = l
h.q = l
h.u = i
l.u = a
i.p = l
i.q = l
i.u = h
assert a.s.u.q.p.u.txt == "a"