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

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

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

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

m = A("m")
a = B("a")
l = C("l")
d = D("d")
b = C("b")
g = D("g")
h = D("h")
i = A("i")

m.q = a
m.v = a
m.p = d
a.q = m
l.r = g
l.u = h
l.o = a
d.q = m
b.r = g
b.u = h
b.o = a
g.q = m
h.q = i
i.q = a
i.v = a
i.p = g
assert m.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: B = None
        self.p: D = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
l = C("l")
d = D("d")
b = C("b")
g = D("g")
h = D("h")
i = A("i")

m.q = a
m.v = a
m.p = d
a.q = m
l.r = g
l.u = h
l.o = a
d.q = m
b.r = g
b.u = h
b.o = a
g.q = m
h.q = i
i.q = a
i.v = a
i.p = g
assert m.q.q.q.q.txt == "m"