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

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

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

c.u = f
b.o = c
b.s = j
j.o = f
j.s = b
g.u = f
f.u = g
assert b.s.o.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.o: A = None
        self.s: B = None
        self.txt = txt

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

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