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

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

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

d = A("d")
c = B("c")
k = C("k")
h = C("h")
f = C("f")
g = B("g")
b = A("b")

d.q = b
d.t = g
c.s = f
k.p = d
h.p = b
f.p = d
g.s = h
b.q = d
b.t = c
assert d.t.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: B = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
k = C("k")
h = C("h")
f = C("f")
g = B("g")
b = A("b")

d.q = b
d.t = g
c.s = f
k.p = d
h.p = b
f.p = d
g.s = h
b.q = d
b.t = c
assert d.t.s.p.txt == "b"