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

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

i = A("i")
g = B("g")
j = B("j")
f = A("f")
n = B("n")
b = A("b")
c = B("c")
m = B("m")
a = A("a")
d = A("d")

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

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

i = A("i")
g = B("g")
j = B("j")
f = A("f")
n = B("n")
b = A("b")
c = B("c")
m = B("m")
a = A("a")
d = A("d")

i.p = d
g.o = n
g.w = i
j.o = c
j.w = f
f.p = d
n.o = g
n.w = f
b.p = f
c.o = j
c.w = a
m.o = j
m.w = f
a.p = b
d.p = b
assert a.p.p.p.p.p.p.p.txt == "b"