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

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

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

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

m = A("m")
n = B("n")
d = C("d")
g = D("g")
a = B("a")
h = A("h")

m.r = g
m.s = d
n.s = d
n.o = m
d.p = m
d.u = h
d.s = a
d.v = a
g.o = d
g.y = a
g.p = a
a.s = d
a.o = m
h.r = g
h.s = d
assert a.o.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: C = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
d = C("d")
g = D("g")
a = B("a")
h = A("h")

m.r = g
m.s = d
n.s = d
n.o = m
d.p = m
d.u = h
d.s = a
d.v = a
g.o = d
g.y = a
g.p = a
a.s = d
a.o = m
h.r = g
h.s = d
assert a.o.s.u.s.txt == "d"