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

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

f = A("f")
a = B("a")
m = A("m")
g = A("g")

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

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

f = A("f")
a = B("a")
m = A("m")
g = A("g")

f.z = a
a.x = g
m.z = a
g.z = a
assert f.z.x.z.x.txt == "g"