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

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

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

m.x = i
g.w = m
g.u = f
f.w = m
f.u = g
k.w = b
k.u = f
b.x = i
i.x = m
assert k.w.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

m.x = i
g.w = m
g.u = f
f.w = m
f.u = g
k.w = b
k.u = f
b.x = i
i.x = m
assert k.w.x.x.x.txt == "i"