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

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

n = A("n")
b = B("b")
c = B("c")
f = B("f")
j = B("j")
g = A("g")

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

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

n = A("n")
b = B("b")
c = B("c")
f = B("f")
j = B("j")
g = A("g")

n.s = g
b.u = c
c.u = f
f.u = c
j.u = f
g.s = n
assert b.u.u.u.u.txt == "f"