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

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

j = A("j")
i = B("i")
m = A("m")
e = A("e")
n = B("n")
g = B("g")
l = A("l")

j.z = n
j.x = l
i.z = m
m.z = g
m.x = j
e.z = n
e.x = l
n.z = e
g.z = j
l.z = g
l.x = j
assert e.z.z.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.x: A = None
        self.txt = txt

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

j = A("j")
i = B("i")
m = A("m")
e = A("e")
n = B("n")
g = B("g")
l = A("l")

j.z = n
j.x = l
i.z = m
m.z = g
m.x = j
e.z = n
e.x = l
n.z = e
g.z = j
l.z = g
l.x = j
assert e.z.z.x.x.x.x.txt == "j"