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

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.q: B = None
        self.txt = txt

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

i = A("i")
f = B("f")
n = C("n")
m = D("m")
a = B("a")
h = B("h")
g = B("g")
k = B("k")

i.v = h
f.o = m
f.r = n
n.v = m
n.q = f
m.o = i
a.o = m
a.r = n
h.o = m
h.r = n
g.o = m
g.r = n
k.o = m
k.r = n
assert i.v.r.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.q: B = None
        self.txt = txt

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

i = A("i")
f = B("f")
n = C("n")
m = D("m")
a = B("a")
h = B("h")
g = B("g")
k = B("k")

i.v = h
f.o = m
f.r = n
n.v = m
n.q = f
m.o = i
a.o = m
a.r = n
h.o = m
h.r = n
g.o = m
g.r = n
k.o = m
k.r = n
assert i.v.r.q.o.txt == "m"