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.txt = txt

h = A("h")
f = B("f")
g = A("g")

h.z = g
f.x = g
g.z = h
assert f.x.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.txt = txt

h = A("h")
f = B("f")
g = A("g")

h.z = g
f.x = g
g.z = h
assert f.x.z.z.txt == "g"