class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.y: B = None
        self.r: B = None
        self.q: E = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

c = A("c")
m = B("m")
f = C("f")
d = D("d")
g = E("g")

c.x = d
c.y = m
c.r = m
c.q = g
m.y = f
m.o = d
f.r = d
f.p = d
f.u = c
d.t = m
d.o = g
g.u = f
assert c.q.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.y: B = None
        self.r: B = None
        self.q: E = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

c = A("c")
m = B("m")
f = C("f")
d = D("d")
g = E("g")

c.x = d
c.y = m
c.r = m
c.q = g
m.y = f
m.o = d
f.r = d
f.p = d
f.u = c
d.t = m
d.o = g
g.u = f
assert c.q.u.p.txt == "d"