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

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

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

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

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

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

g.x = h
g.y = h
f.t = h
f.w = b
b.t = h
b.w = f
h.x = g
h.y = g
assert h.x.y.y.txt == "g"