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

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

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

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

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

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

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

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

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

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

c.q = n
c.p = n
c.r = g
c.s = k
b.x = n
b.w = k
b.v = c
n.r = k
k.w = c
g.x = n
g.w = k
g.v = f
f.q = n
f.p = n
f.r = b
f.s = k
assert g.w.w.q.r.txt == "k"