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

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

h = A("h")
k = B("k")
n = B("n")

h.v = k
k.z = h
n.z = h
assert h.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
n = B("n")

h.v = k
k.z = h
n.z = h
assert h.v.z.v.txt == "k"