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

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

class C:
    def __init__(self, txt: str):
        self.x: E = None
        self.p: E = None
        self.u: D = None
        self.r: B = None
        self.t: B = None
        self.txt = txt

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

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

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

g.q = a
m.p = a
f.x = j
f.p = j
f.u = a
f.r = m
f.t = m
a.q = f
j.u = g
c.q = a
assert f.u.q.u.q.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: E = None
        self.p: E = None
        self.u: D = None
        self.r: B = None
        self.t: B = None
        self.txt = txt

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

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

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

g.q = a
m.p = a
f.x = j
f.p = j
f.u = a
f.r = m
f.t = m
a.q = f
j.u = g
c.q = a
assert f.u.q.u.q.p.u.txt == "g"