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

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

n = A("n")
j = B("j")
k = A("k")
g = A("g")
l = B("l")
i = A("i")
a = A("a")
b = A("b")
h = A("h")

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

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

n = A("n")
j = B("j")
k = A("k")
g = A("g")
l = B("l")
i = A("i")
a = A("a")
b = A("b")
h = A("h")

n.x = j
j.p = l
k.x = j
g.x = l
l.p = j
i.x = j
a.x = l
b.x = j
h.x = j
assert n.x.p.p.txt == "j"