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

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

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

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

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

f.o = g
f.y = g
f.p = c
c.x = a
c.q = f
g.t = c
g.p = c
g.r = a
a.u = c
assert c.q.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.p: B = None
        self.y: C = None
        self.txt = txt

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

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

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

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

f.o = g
f.y = g
f.p = c
c.x = a
c.q = f
g.t = c
g.p = c
g.r = a
a.u = c
assert c.q.p.x.txt == "a"