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

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

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

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

class E:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: D = None
        self.v: D = None
        self.y: B = None
        self.s: C = None
        self.txt = txt

b = A("b")
e = B("e")
f = C("f")
d = D("d")
a = E("a")
c = A("c")
g = D("g")

b.t = a
e.p = a
e.w = a
f.x = d
d.x = b
d.s = b
d.q = f
d.r = f
d.y = a
a.w = f
a.s = f
a.r = g
a.v = d
a.y = e
c.t = a
g.x = c
g.s = c
g.q = f
g.r = f
g.y = a
assert g.s.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: E = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: D = None
        self.v: D = None
        self.y: B = None
        self.s: C = None
        self.txt = txt

b = A("b")
e = B("e")
f = C("f")
d = D("d")
a = E("a")
c = A("c")
g = D("g")

b.t = a
e.p = a
e.w = a
f.x = d
d.x = b
d.s = b
d.q = f
d.r = f
d.y = a
a.w = f
a.s = f
a.r = g
a.v = d
a.y = e
c.t = a
g.x = c
g.s = c
g.q = f
g.r = f
g.y = a
assert g.s.t.r.txt == "g"