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

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

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

a.y = c
a.v = e
c.s = b
b.s = c
e.y = c
e.v = a
assert b.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.v: A = None
        self.txt = txt

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

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

a.y = c
a.v = e
c.s = b
b.s = c
e.y = c
e.v = a
assert b.s.s.s.txt == "c"