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

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

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

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

b.p = c
b.q = h
h.y = b
c.t = b
c.u = h
m.t = b
m.u = h
assert b.p.t.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: B = None
        self.txt = txt

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

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

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

b.p = c
b.q = h
h.y = b
c.t = b
c.u = h
m.t = b
m.u = h
assert b.p.t.q.y.txt == "b"