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

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

g = A("g")
f = B("f")
l = B("l")
k = A("k")
c = B("c")
i = B("i")
m = A("m")
e = B("e")
d = A("d")
a = A("a")

g.o = i
g.p = k
f.w = a
l.w = a
k.o = l
k.p = a
c.w = a
i.w = a
m.o = f
m.p = d
e.w = d
d.o = i
d.p = a
a.o = c
a.p = g
assert k.o.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: A = None
        self.txt = txt

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

g = A("g")
f = B("f")
l = B("l")
k = A("k")
c = B("c")
i = B("i")
m = A("m")
e = B("e")
d = A("d")
a = A("a")

g.o = i
g.p = k
f.w = a
l.w = a
k.o = l
k.p = a
c.w = a
i.w = a
m.o = f
m.p = d
e.w = d
d.o = i
d.p = a
a.o = c
a.p = g
assert k.o.w.o.w.txt == "a"