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

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

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

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

b = A("b")
g = B("g")
f = C("f")
a = D("a")
d = B("d")
j = B("j")
k = C("k")

b.p = g
g.p = j
f.s = g
f.q = b
f.z = a
a.r = j
a.u = b
d.p = g
j.p = d
k.s = j
k.q = b
k.z = a
assert j.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
f = C("f")
a = D("a")
d = B("d")
j = B("j")
k = C("k")

b.p = g
g.p = j
f.s = g
f.q = b
f.z = a
a.r = j
a.u = b
d.p = g
j.p = d
k.s = j
k.q = b
k.z = a
assert j.p.p.p.txt == "j"