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

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

h = A("h")
m = B("m")
j = A("j")
k = B("k")
c = A("c")

h.z = c
m.v = j
m.r = k
j.z = c
k.v = j
k.r = m
c.z = h
assert k.r.v.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

h = A("h")
m = B("m")
j = A("j")
k = B("k")
c = A("c")

h.z = c
m.v = j
m.r = k
j.z = c
k.v = j
k.r = m
c.z = h
assert k.r.v.z.z.txt == "h"