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

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

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

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

k = A("k")
f = B("f")
g = C("g")
d = D("d")
e = A("e")

k.q = g
f.q = d
f.o = d
f.v = k
g.x = f
d.r = g
e.q = g
assert f.v.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

k = A("k")
f = B("f")
g = C("g")
d = D("d")
e = A("e")

k.q = g
f.q = d
f.o = d
f.v = k
g.x = f
d.r = g
e.q = g
assert f.v.q.x.txt == "f"