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

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

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

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

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

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

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