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

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

j = A("j")
i = B("i")
m = B("m")
g = A("g")
d = B("d")
l = A("l")
c = B("c")
a = B("a")
k = A("k")

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

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

j = A("j")
i = B("i")
m = B("m")
g = A("g")
d = B("d")
l = A("l")
c = B("c")
a = B("a")
k = A("k")

j.v = k
i.z = m
i.r = k
m.z = i
m.r = j
g.v = l
d.z = m
d.r = l
l.v = g
c.z = m
c.r = j
a.z = m
a.r = g
k.v = j
assert d.z.r.v.v.v.v.txt == "j"