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

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

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

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

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

k.y = n
k.w = n
k.r = n
b.z = a
f.q = n
f.y = c
f.r = c
f.p = a
n.p = a
n.z = f
n.x = f
a.y = n
a.w = n
a.r = n
c.q = n
c.y = f
c.r = f
c.p = a
assert c.p.w.z.q.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.w: D = None
        self.r: D = None
        self.txt = txt

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

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

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

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

k.y = n
k.w = n
k.r = n
b.z = a
f.q = n
f.y = c
f.r = c
f.p = a
n.p = a
n.z = f
n.x = f
a.y = n
a.w = n
a.r = n
c.q = n
c.y = f
c.r = f
c.p = a
assert c.p.w.z.q.p.r.txt == "n"