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

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

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

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

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

d.o = l
d.y = a
a.q = l
a.p = d
l.x = a
l.w = a
l.s = d
l.r = g
n.w = l
n.z = l
n.q = d
g.x = a
g.w = a
g.s = d
g.r = l
assert g.s.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: B = None
        self.txt = txt

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

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

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

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

d.o = l
d.y = a
a.q = l
a.p = d
l.x = a
l.w = a
l.s = d
l.r = g
n.w = l
n.z = l
n.q = d
g.x = a
g.w = a
g.s = d
g.r = l
assert g.s.y.p.txt == "d"