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

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

class C:
    def __init__(self, txt: str):
        self.z: D = None
        self.p: E = None
        self.v: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.w: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

d = A("d")
m = B("m")
g = C("g")
c = D("c")
i = E("i")
b = A("b")
a = B("a")

d.s = g
d.q = a
d.r = b
m.p = d
m.q = b
g.z = c
g.p = i
g.v = i
c.w = i
i.p = d
b.s = g
b.q = a
b.r = d
a.p = d
a.q = b
assert i.p.s.v.p.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.q: B = None
        self.r: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: D = None
        self.p: E = None
        self.v: E = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.w: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

d = A("d")
m = B("m")
g = C("g")
c = D("c")
i = E("i")
b = A("b")
a = B("a")

d.s = g
d.q = a
d.r = b
m.p = d
m.q = b
g.z = c
g.p = i
g.v = i
c.w = i
i.p = d
b.s = g
b.q = a
b.r = d
a.p = d
a.q = b
assert i.p.s.v.p.r.s.txt == "g"