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

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

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

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

i = A("i")
b = B("b")
m = C("m")
a = D("a")
j = A("j")

i.t = a
b.u = a
m.o = b
m.u = b
m.t = j
m.v = a
a.p = m
j.t = a
assert b.u.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

i = A("i")
b = B("b")
m = C("m")
a = D("a")
j = A("j")

i.t = a
b.u = a
m.o = b
m.u = b
m.t = j
m.v = a
a.p = m
j.t = a
assert b.u.p.o.txt == "b"