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

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

f = A("f")
a = B("a")
c = B("c")
b = A("b")
g = A("g")
i = B("i")
h = B("h")
k = B("k")
e = A("e")
j = A("j")

f.p = b
f.x = e
a.w = h
a.r = g
c.w = a
c.r = b
b.p = g
b.x = e
g.p = f
g.x = e
i.w = k
i.r = f
h.w = k
h.r = f
k.w = c
k.r = g
e.p = f
e.x = f
j.p = f
j.x = e
assert b.x.x.x.x.p.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: A = None
        self.txt = txt

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

f = A("f")
a = B("a")
c = B("c")
b = A("b")
g = A("g")
i = B("i")
h = B("h")
k = B("k")
e = A("e")
j = A("j")

f.p = b
f.x = e
a.w = h
a.r = g
c.w = a
c.r = b
b.p = g
b.x = e
g.p = f
g.x = e
i.w = k
i.r = f
h.w = k
h.r = f
k.w = c
k.r = g
e.p = f
e.x = f
j.p = f
j.x = e
assert b.x.x.x.x.p.x.x.x.txt == "e"