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

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

n = A("n")
m = B("m")
l = A("l")
f = A("f")
j = B("j")
a = B("a")

n.z = f
n.t = l
m.s = f
m.r = f
l.z = n
l.t = n
f.z = n
f.t = n
j.s = n
j.r = n
a.s = n
a.r = n
assert m.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.t: A = None
        self.txt = txt

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

n = A("n")
m = B("m")
l = A("l")
f = A("f")
j = B("j")
a = B("a")

n.z = f
n.t = l
m.s = f
m.r = f
l.z = n
l.t = n
f.z = n
f.t = n
j.s = n
j.r = n
a.s = n
a.r = n
assert m.r.z.z.txt == "f"