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

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

b = A("b")
f = B("f")
c = A("c")
g = B("g")

b.v = c
f.o = c
c.v = b
g.o = c
assert b.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

b = A("b")
f = B("f")
c = A("c")
g = B("g")

b.v = c
f.o = c
c.v = b
g.o = c
assert b.v.v.v.v.txt == "b"