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.txt = txt

i = A("i")
a = B("a")
h = A("h")
k = B("k")

i.v = k
a.v = i
h.v = a
k.v = h
assert k.v.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.txt = txt

i = A("i")
a = B("a")
h = A("h")
k = B("k")

i.v = k
a.v = i
h.v = a
k.v = h
assert k.v.v.v.txt == "i"