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

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

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

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

b = A("b")
c = B("c")
f = C("f")
a = D("a")
g = D("g")
d = C("d")
l = D("l")

b.s = c
b.y = d
c.z = g
f.q = d
a.p = b
a.t = l
a.w = l
g.p = b
g.t = l
g.w = a
d.q = f
l.p = b
l.t = g
l.w = a
assert b.s.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: C = None
        self.txt = txt

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

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

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

b = A("b")
c = B("c")
f = C("f")
a = D("a")
g = D("g")
d = C("d")
l = D("l")

b.s = c
b.y = d
c.z = g
f.q = d
a.p = b
a.t = l
a.w = l
g.p = b
g.t = l
g.w = a
d.q = f
l.p = b
l.t = g
l.w = a
assert b.s.z.p.txt == "b"