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

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

l = A("l")
g = B("g")
i = A("i")
d = B("d")
a = A("a")
m = A("m")
f = B("f")
k = B("k")
n = A("n")
b = B("b")

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

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

l = A("l")
g = B("g")
i = A("i")
d = B("d")
a = A("a")
m = A("m")
f = B("f")
k = B("k")
n = A("n")
b = B("b")

l.w = g
l.o = k
g.x = d
i.w = g
i.o = f
d.x = k
a.w = k
a.o = g
m.w = f
m.o = f
f.x = b
k.x = d
n.w = f
n.o = d
b.x = k
assert g.x.x.x.x.txt == "k"