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

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

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

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

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

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

g.u = k
m.u = g
m.s = i
b.u = g
b.s = i
i.u = k
k.u = g
assert g.u.u.u.u.u.txt == "k"