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

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

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

m.q = n
h.y = a
h.s = b
a.q = m
n.q = m
b.y = m
b.s = h
assert b.s.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

m.q = n
h.y = a
h.s = b
a.q = m
n.q = m
b.y = m
b.s = h
assert b.s.y.q.txt == "m"