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

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

b = A("b")
g = B("g")
d = B("d")
h = A("h")

b.v = g
g.y = h
d.y = b
h.v = g
assert h.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

b = A("b")
g = B("g")
d = B("d")
h = A("h")

b.v = g
g.y = h
d.y = b
h.v = g
assert h.v.y.v.txt == "g"