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

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

b = A("b")
a = B("a")
m = B("m")
c = A("c")

b.y = c
a.w = m
m.w = a
c.y = b
assert b.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
m = B("m")
c = A("c")

b.y = c
a.w = m
m.w = a
c.y = b
assert b.y.y.y.txt == "c"