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

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

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

g.w = h
g.y = f
f.z = g
h.w = g
h.y = f
assert f.z.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.y: B = None
        self.txt = txt

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

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

g.w = h
g.y = f
f.z = g
h.w = g
h.y = f
assert f.z.w.y.txt == "f"