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

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

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

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

n = A("n")
j = B("j")
f = C("f")
b = D("b")
h = C("h")

n.r = j
j.p = n
j.u = f
f.t = j
f.q = j
b.t = j
b.x = n
h.t = j
h.q = j
assert b.x.r.p.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
f = C("f")
b = D("b")
h = C("h")

n.r = j
j.p = n
j.u = f
f.t = j
f.q = j
b.t = j
b.x = n
h.t = j
h.q = j
assert b.x.r.p.r.u.txt == "f"