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

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

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

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

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

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

j.r = n
j.z = c
g.v = i
g.u = n
i.v = g
i.u = n
c.r = i
c.z = m
n.v = g
n.u = g
m.r = n
m.z = c
assert m.z.z.z.txt == "c"