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

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

e = A("e")
c = B("c")
k = A("k")
l = B("l")
a = B("a")
m = B("m")
g = A("g")

e.z = g
c.r = g
k.z = e
l.r = g
a.r = e
m.r = e
g.z = k
assert c.r.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

e = A("e")
c = B("c")
k = A("k")
l = B("l")
a = B("a")
m = B("m")
g = A("g")

e.z = g
c.r = g
k.z = e
l.r = g
a.r = e
m.r = e
g.z = k
assert c.r.z.z.z.txt == "g"