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

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

e = A("e")
a = B("a")
f = B("f")
g = B("g")
c = A("c")
m = A("m")
h = B("h")
d = B("d")
i = A("i")
j = B("j")

e.p = h
e.y = c
a.x = g
f.x = h
g.x = f
c.p = f
c.y = e
m.p = h
m.y = e
h.x = g
d.x = g
i.p = j
i.y = e
j.x = f
assert m.y.p.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: A = None
        self.txt = txt

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

e = A("e")
a = B("a")
f = B("f")
g = B("g")
c = A("c")
m = A("m")
h = B("h")
d = B("d")
i = A("i")
j = B("j")

e.p = h
e.y = c
a.x = g
f.x = h
g.x = f
c.p = f
c.y = e
m.p = h
m.y = e
h.x = g
d.x = g
i.p = j
i.y = e
j.x = f
assert m.y.p.x.x.x.txt == "h"