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

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

k = A("k")
a = B("a")
g = A("g")
n = A("n")
f = B("f")

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

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

k = A("k")
a = B("a")
g = A("g")
n = A("n")
f = B("f")

k.o = g
k.w = a
a.s = f
g.o = k
g.w = f
n.o = k
n.w = f
f.s = a
assert k.o.w.s.s.s.txt == "a"