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

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

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

h = A("h")
b = B("b")
m = C("m")
a = C("a")

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

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

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

h = A("h")
b = B("b")
m = C("m")
a = C("a")

h.w = a
b.w = h
b.u = a
b.r = m
m.q = h
m.s = a
m.r = a
a.q = h
a.s = m
a.r = m
assert a.s.r.q.txt == "h"