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

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

n = A("n")
e = B("e")
d = B("d")
g = B("g")
f = B("f")
k = A("k")

n.z = k
e.r = d
e.q = g
d.r = e
d.q = e
g.r = f
g.q = f
f.r = e
f.q = g
k.z = n
assert n.z.z.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.r: B = None
        self.q: B = None
        self.txt = txt

n = A("n")
e = B("e")
d = B("d")
g = B("g")
f = B("f")
k = A("k")

n.z = k
e.r = d
e.q = g
d.r = e
d.q = e
g.r = f
g.q = f
f.r = e
f.q = g
k.z = n
assert n.z.z.z.z.txt == "n"