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

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

k = A("k")
n = B("n")
g = A("g")
e = B("e")

k.s = n
n.u = k
n.o = g
g.s = n
e.u = k
e.o = k
assert k.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k = A("k")
n = B("n")
g = A("g")
e = B("e")

k.s = n
n.u = k
n.o = g
g.s = n
e.u = k
e.o = k
assert k.s.o.s.txt == "n"