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

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

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

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

a = A("a")
g = B("g")
d = C("d")
f = D("f")

a.x = d
g.r = a
g.t = a
d.o = g
d.r = a
f.x = a
f.t = a
assert d.r.x.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

a = A("a")
g = B("g")
d = C("d")
f = D("f")

a.x = d
g.r = a
g.t = a
d.o = g
d.r = a
f.x = a
f.t = a
assert d.r.x.o.t.txt == "a"