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

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

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

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

l = A("l")
g = B("g")
k = C("k")
j = D("j")
f = B("f")

l.p = j
l.t = g
g.t = l
g.r = k
k.t = j
j.s = k
f.t = l
f.r = k
assert f.t.p.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.t: B = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
k = C("k")
j = D("j")
f = B("f")

l.p = j
l.t = g
g.t = l
g.r = k
k.t = j
j.s = k
f.t = l
f.r = k
assert f.t.p.s.t.txt == "j"