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.w: A = None
        self.txt = txt

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

l.v = m
g.o = l
g.w = l
m.v = l
assert m.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.w: A = None
        self.txt = txt

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

l.v = m
g.o = l
g.w = l
m.v = l
assert m.v.v.v.txt == "l"