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

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

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

m.z = j
m.s = d
n.r = i
j.r = m
i.z = c
i.s = d
c.r = d
l.r = d
d.z = g
d.s = i
f.r = m
g.r = m
assert c.r.z.r.s.z.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.s: A = None
        self.txt = txt

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

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

m.z = j
m.s = d
n.r = i
j.r = m
i.z = c
i.s = d
c.r = d
l.r = d
d.z = g
d.s = i
f.r = m
g.r = m
assert c.r.z.r.s.z.r.z.r.txt == "m"