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

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

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

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

g = A("g")
m = B("m")
i = C("i")
d = D("d")

g.o = d
g.r = m
m.r = d
m.x = d
m.t = i
i.x = d
d.x = i
d.v = m
d.r = m
d.t = g
assert i.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.r: B = None
        self.txt = txt

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

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

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

g = A("g")
m = B("m")
i = C("i")
d = D("d")

g.o = d
g.r = m
m.r = d
m.x = d
m.t = i
i.x = d
d.x = i
d.v = m
d.r = m
d.t = g
assert i.x.x.x.txt == "d"