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

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

a = A("a")
l = B("l")
h = A("h")
b = B("b")

a.v = h
l.w = b
l.v = a
h.v = a
b.w = l
b.v = a
assert b.w.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.w: B = None
        self.v: A = None
        self.txt = txt

a = A("a")
l = B("l")
h = A("h")
b = B("b")

a.v = h
l.w = b
l.v = a
h.v = a
b.w = l
b.v = a
assert b.w.v.v.txt == "h"