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

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

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

i.v = c
i.w = b
f.s = i
c.v = i
c.w = b
b.s = c
assert b.s.v.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: B = None
        self.txt = txt

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

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

i.v = c
i.w = b
f.s = i
c.v = i
c.w = b
b.s = c
assert b.s.v.w.s.txt == "c"