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

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

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

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

f = A("f")
c = B("c")
k = C("k")
n = D("n")
e = A("e")
g = C("g")

f.s = k
f.x = e
f.q = c
c.r = e
k.t = n
k.q = n
k.r = g
k.w = g
n.w = k
e.s = k
e.x = f
e.q = c
g.t = n
g.q = n
g.r = k
g.w = k
assert g.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.x: A = None
        self.q: B = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
k = C("k")
n = D("n")
e = A("e")
g = C("g")

f.s = k
f.x = e
f.q = c
c.r = e
k.t = n
k.q = n
k.r = g
k.w = g
n.w = k
e.s = k
e.x = f
e.q = c
g.t = n
g.q = n
g.r = k
g.w = k
assert g.q.w.r.txt == "g"