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

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

n = A("n")
m = B("m")
i = B("i")
j = A("j")
h = A("h")
f = A("f")
l = A("l")
g = A("g")
d = B("d")
b = B("b")

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

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

n = A("n")
m = B("m")
i = B("i")
j = A("j")
h = A("h")
f = A("f")
l = A("l")
g = A("g")
d = B("d")
b = B("b")

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