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

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

l = A("l")
a = B("a")
c = A("c")

l.y = c
a.w = c
c.y = l
assert a.w.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: A = None
        self.txt = txt

l = A("l")
a = B("a")
c = A("c")

l.y = c
a.w = c
c.y = l
assert a.w.y.y.txt == "c"