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

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

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

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

b = A("b")
j = B("j")
h = C("h")
i = D("i")
d = D("d")
n = B("n")
a = D("a")
g = D("g")
l = C("l")

b.q = i
j.o = b
j.t = d
h.p = d
i.r = l
d.r = h
n.o = b
n.t = a
a.r = h
g.r = l
l.p = a
assert j.t.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

b = A("b")
j = B("j")
h = C("h")
i = D("i")
d = D("d")
n = B("n")
a = D("a")
g = D("g")
l = C("l")

b.q = i
j.o = b
j.t = d
h.p = d
i.r = l
d.r = h
n.o = b
n.t = a
a.r = h
g.r = l
l.p = a
assert j.t.r.p.r.txt == "h"