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

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

n = A("n")
j = B("j")
d = A("d")
c = A("c")
g = B("g")
e = B("e")

n.z = d
j.x = d
j.s = e
d.z = c
c.z = d
g.x = n
g.s = j
e.x = n
e.s = j
assert d.z.z.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.x: A = None
        self.s: B = None
        self.txt = txt

n = A("n")
j = B("j")
d = A("d")
c = A("c")
g = B("g")
e = B("e")

n.z = d
j.x = d
j.s = e
d.z = c
c.z = d
g.x = n
g.s = j
e.x = n
e.s = j
assert d.z.z.z.z.z.z.txt == "d"