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

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

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

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

m = A("m")
k = B("k")
f = C("f")
b = D("b")

m.y = f
k.r = b
f.p = b
f.o = k
b.x = f
assert b.x.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
f = C("f")
b = D("b")

m.y = f
k.r = b
f.p = b
f.o = k
b.x = f
assert b.x.o.r.txt == "b"