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

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

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

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

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

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

n.v = f
n.y = k
h.z = n
f.z = n
d.v = h
d.y = k
k.v = f
k.y = n
assert n.y.v.z.y.v.txt == "f"