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

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

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

m.u = f
m.x = i
f.y = m
f.s = i
i.u = f
i.x = m
g.u = f
g.x = i
assert m.u.y.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.x: A = None
        self.txt = txt

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

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

m.u = f
m.x = i
f.y = m
f.s = i
i.u = f
i.x = m
g.u = f
g.x = i
assert m.u.y.x.u.txt == "f"