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

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

d = A("d")
k = B("k")
f = B("f")
g = A("g")

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

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

d = A("d")
k = B("k")
f = B("f")
g = A("g")

d.x = g
d.s = f
k.u = d
k.x = f
f.u = g
f.x = k
g.x = d
g.s = f
assert f.x.u.s.txt == "f"