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

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

class C:
    def __init__(self, txt: str):
        self.y: C = None
        self.s: B = None
        self.p: B = None
        self.txt = txt

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

b = A("b")
n = B("n")
c = C("c")
k = D("k")
h = D("h")
l = D("l")
f = B("f")
d = C("d")

b.x = c
b.r = f
n.r = c
n.z = c
n.q = h
n.x = f
c.y = d
c.s = f
c.p = n
k.s = b
h.s = b
l.s = b
f.r = d
f.z = d
f.q = k
f.x = n
d.y = c
d.s = n
d.p = n
assert f.r.y.s.x.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.r: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: C = None
        self.s: B = None
        self.p: B = None
        self.txt = txt

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

b = A("b")
n = B("n")
c = C("c")
k = D("k")
h = D("h")
l = D("l")
f = B("f")
d = C("d")

b.x = c
b.r = f
n.r = c
n.z = c
n.q = h
n.x = f
c.y = d
c.s = f
c.p = n
k.s = b
h.s = b
l.s = b
f.r = d
f.z = d
f.q = k
f.x = n
d.y = c
d.s = n
d.p = n
assert f.r.y.s.x.q.s.txt == "b"