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

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

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

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

n = A("n")
b = B("b")
g = C("g")
k = D("k")
i = B("i")
d = A("d")

n.q = g
b.r = n
g.o = k
k.r = n
k.p = d
k.u = b
i.r = d
d.q = g
assert n.q.o.u.r.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

n = A("n")
b = B("b")
g = C("g")
k = D("k")
i = B("i")
d = A("d")

n.q = g
b.r = n
g.o = k
k.r = n
k.p = d
k.u = b
i.r = d
d.q = g
assert n.q.o.u.r.q.o.txt == "k"