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

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

d = A("d")
k = B("k")
a = A("a")
n = B("n")

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

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

d = A("d")
k = B("k")
a = A("a")
n = B("n")

d.z = a
k.y = n
k.v = d
a.z = d
n.y = k
n.v = d
assert k.y.y.y.txt == "n"