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.o: A = None
        self.txt = txt

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

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

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

i.y = b
a.w = b
a.o = i
b.y = i
c.w = b
c.o = b
assert i.y.y.y.txt == "b"