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.s: C = None
        self.y: B = None
        self.txt = txt

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

f = A("f")
n = B("n")
m = C("m")
k = C("k")
g = B("g")
b = A("b")

f.u = b
f.y = b
n.s = m
n.y = g
m.u = k
k.u = m
g.s = m
g.y = n
b.u = f
b.y = f
assert f.y.y.y.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.s: C = None
        self.y: B = None
        self.txt = txt

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

f = A("f")
n = B("n")
m = C("m")
k = C("k")
g = B("g")
b = A("b")

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