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

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

f = A("f")
k = B("k")
n = A("n")
b = A("b")

f.u = b
f.y = n
k.u = n
k.s = n
n.u = f
n.y = f
b.u = f
b.y = f
assert b.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.y: A = None
        self.txt = txt

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

f = A("f")
k = B("k")
n = A("n")
b = A("b")

f.u = b
f.y = n
k.u = n
k.s = n
n.u = f
n.y = f
b.u = f
b.y = f
assert b.u.u.u.u.txt == "b"