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

class B:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: A = None
        self.x: D = None
        self.z: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: B = None
        self.x: C = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: D = None
        self.v: B = None
        self.o: C = None
        self.txt = txt

f = A("f")
g = B("g")
l = C("l")
e = D("e")
i = B("i")
a = D("a")
m = C("m")
n = A("n")

f.r = n
g.w = i
g.v = n
g.x = a
g.z = e
l.z = m
l.x = m
l.o = g
e.r = n
e.w = a
e.v = g
e.o = m
i.w = g
i.v = n
i.x = a
i.z = a
a.r = f
a.w = e
a.v = g
a.o = l
m.z = l
m.x = l
m.o = g
n.r = f
assert g.x.v.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: A = None
        self.x: D = None
        self.z: D = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: B = None
        self.x: C = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: D = None
        self.v: B = None
        self.o: C = None
        self.txt = txt

f = A("f")
g = B("g")
l = C("l")
e = D("e")
i = B("i")
a = D("a")
m = C("m")
n = A("n")

f.r = n
g.w = i
g.v = n
g.x = a
g.z = e
l.z = m
l.x = m
l.o = g
e.r = n
e.w = a
e.v = g
e.o = m
i.w = g
i.v = n
i.x = a
i.z = a
a.r = f
a.w = e
a.v = g
a.o = l
m.z = l
m.x = l
m.o = g
n.r = f
assert g.x.v.x.r.r.txt == "n"