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

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

e = A("e")
g = B("g")
k = B("k")
l = A("l")
a = B("a")
d = B("d")
j = B("j")
h = B("h")
b = A("b")

e.x = j
e.w = j
g.p = b
k.p = b
l.x = g
l.w = j
a.p = e
d.p = l
j.p = b
h.p = l
b.x = a
b.w = d
assert k.p.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: B = None
        self.txt = txt

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

e = A("e")
g = B("g")
k = B("k")
l = A("l")
a = B("a")
d = B("d")
j = B("j")
h = B("h")
b = A("b")

e.x = j
e.w = j
g.p = b
k.p = b
l.x = g
l.w = j
a.p = e
d.p = l
j.p = b
h.p = l
b.x = a
b.w = d
assert k.p.x.p.txt == "e"