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

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

h = A("h")
g = B("g")
j = A("j")
f = B("f")
c = A("c")

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

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

h = A("h")
g = B("g")
j = A("j")
f = B("f")
c = A("c")

h.s = c
h.u = f
g.u = f
j.s = c
j.u = f
f.u = g
c.s = h
c.u = f
assert c.u.u.u.txt == "f"