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

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

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

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

n = A("n")
a = B("a")
b = C("b")
c = D("c")
i = B("i")
d = A("d")

n.y = a
n.o = c
a.t = b
a.r = b
a.z = d
b.w = i
b.s = a
b.p = n
b.q = c
c.q = b
i.t = b
i.r = b
i.z = d
d.y = a
d.o = c
assert d.y.r.s.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: D = None
        self.txt = txt

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

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

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

n = A("n")
a = B("a")
b = C("b")
c = D("c")
i = B("i")
d = A("d")

n.y = a
n.o = c
a.t = b
a.r = b
a.z = d
b.w = i
b.s = a
b.p = n
b.q = c
c.q = b
i.t = b
i.r = b
i.z = d
d.y = a
d.o = c
assert d.y.r.s.r.q.q.txt == "b"