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

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

e = A("e")
f = B("f")
a = B("a")
n = B("n")
c = B("c")
g = A("g")

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

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

e = A("e")
f = B("f")
a = B("a")
n = B("n")
c = B("c")
g = A("g")

e.x = a
f.z = e
a.z = g
n.z = e
c.z = e
g.x = c
assert f.z.x.z.x.z.x.txt == "a"