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

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

g = A("g")
f = B("f")
l = A("l")
k = A("k")
h = B("h")
e = A("e")
b = B("b")
j = A("j")
m = A("m")
i = B("i")

g.p = h
f.x = g
f.o = l
l.p = f
k.p = f
h.x = e
h.o = e
e.p = i
b.x = k
b.o = k
j.p = f
m.p = f
i.x = e
i.o = k
assert f.o.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
l = A("l")
k = A("k")
h = B("h")
e = A("e")
b = B("b")
j = A("j")
m = A("m")
i = B("i")

g.p = h
f.x = g
f.o = l
l.p = f
k.p = f
h.x = e
h.o = e
e.p = i
b.x = k
b.o = k
j.p = f
m.p = f
i.x = e
i.o = k
assert f.o.p.o.p.txt == "f"