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

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

j = A("j")
a = B("a")
n = B("n")
h = B("h")
k = B("k")
f = B("f")
d = B("d")
m = A("m")
g = B("g")
l = B("l")

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

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

j = A("j")
a = B("a")
n = B("n")
h = B("h")
k = B("k")
f = B("f")
d = B("d")
m = A("m")
g = B("g")
l = B("l")

j.p = l
a.p = j
n.p = m
h.p = m
k.p = j
f.p = j
d.p = m
m.p = d
g.p = m
l.p = m
assert j.p.p.p.p.p.p.txt == "m"