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

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

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

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

b = A("b")
k = B("k")
i = C("i")
m = D("m")
n = B("n")

b.y = m
b.x = m
b.t = n
b.p = i
k.u = b
i.o = n
i.v = b
m.x = i
n.u = b
assert i.v.t.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.x: D = None
        self.t: B = None
        self.p: C = None
        self.txt = txt

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

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

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

b = A("b")
k = B("k")
i = C("i")
m = D("m")
n = B("n")

b.y = m
b.x = m
b.t = n
b.p = i
k.u = b
i.o = n
i.v = b
m.x = i
n.u = b
assert i.v.t.u.p.txt == "i"