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

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

d = A("d")
k = B("k")
c = A("c")
n = B("n")
i = A("i")

d.r = c
d.y = n
k.z = n
c.r = i
c.y = k
n.z = k
i.r = c
i.y = n
assert n.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.y: B = None
        self.txt = txt

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

d = A("d")
k = B("k")
c = A("c")
n = B("n")
i = A("i")

d.r = c
d.y = n
k.z = n
c.r = i
c.y = k
n.z = k
i.r = c
i.y = n
assert n.z.z.z.z.txt == "n"