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

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

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

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

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

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

l.w = b
l.v = b
f.p = b
f.v = i
b.w = i
b.v = l
i.w = b
i.v = l
assert b.v.w.w.v.txt == "l"