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

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

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

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

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

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

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