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

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

m = A("m")
f = B("f")
l = A("l")
g = B("g")

m.v = g
f.v = l
f.x = g
l.v = g
g.v = m
g.x = f
assert g.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

m = A("m")
f = B("f")
l = A("l")
g = B("g")

m.v = g
f.v = l
f.x = g
l.v = g
g.v = m
g.x = f
assert g.x.v.v.txt == "g"