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

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

j = A("j")
i = B("i")
e = A("e")
c = B("c")
n = B("n")
f = B("f")

j.z = f
i.w = e
i.x = e
e.z = n
c.w = j
c.x = e
n.w = e
n.x = j
f.w = j
f.x = e
assert c.w.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
e = A("e")
c = B("c")
n = B("n")
f = B("f")

j.z = f
i.w = e
i.x = e
e.z = n
c.w = j
c.x = e
n.w = e
n.x = j
f.w = j
f.x = e
assert c.w.z.x.z.txt == "n"