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

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

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

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

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

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

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

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

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

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

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