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

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

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

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

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

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

m.z = f
k.r = b
k.p = b
i.r = m
i.p = m
b.z = k
f.r = l
f.p = b
l.z = f
j.r = m
j.p = l
assert l.z.r.z.txt == "f"