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

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

j = A("j")
k = B("k")
m = A("m")
f = B("f")
n = A("n")
i = B("i")
g = B("g")

j.p = n
k.y = g
k.z = n
m.p = j
f.y = i
f.z = j
n.p = m
i.y = g
i.z = m
g.y = i
g.z = j
assert j.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

j = A("j")
k = B("k")
m = A("m")
f = B("f")
n = A("n")
i = B("i")
g = B("g")

j.p = n
k.y = g
k.z = n
m.p = j
f.y = i
f.z = j
n.p = m
i.y = g
i.z = m
g.y = i
g.z = j
assert j.p.p.p.p.txt == "n"