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

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

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

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

n = A("n")
g = B("g")
f = C("f")
c = D("c")
d = D("d")
l = D("l")

n.u = g
n.s = g
g.s = f
f.p = n
f.q = n
f.o = g
c.r = n
c.p = n
c.s = f
d.r = n
d.p = n
d.s = f
l.r = n
l.p = n
l.s = f
assert c.s.o.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: B = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
f = C("f")
c = D("c")
d = D("d")
l = D("l")

n.u = g
n.s = g
g.s = f
f.p = n
f.q = n
f.o = g
c.r = n
c.p = n
c.s = f
d.r = n
d.p = n
d.s = f
l.r = n
l.p = n
l.s = f
assert c.s.o.s.p.txt == "n"