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

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

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

h = A("h")
l = B("l")
m = C("m")
a = C("a")
k = A("k")

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

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

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

h = A("h")
l = B("l")
m = C("m")
a = C("a")
k = A("k")

h.u = m
l.u = a
l.s = m
l.w = h
m.p = a
m.q = l
a.p = m
a.q = l
k.u = a
assert a.p.p.q.u.txt == "a"