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

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

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

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

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

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

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