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

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

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

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

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

l.o = m
b.p = j
b.r = l
f.y = b
a.u = b
a.x = j
a.t = m
m.u = b
m.x = f
m.t = a
j.y = b
assert j.y.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

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

l.o = m
b.p = j
b.r = l
f.y = b
a.u = b
a.x = j
a.t = m
m.u = b
m.x = f
m.t = a
j.y = b
assert j.y.r.o.txt == "m"