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

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

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

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

f = A("f")
l = B("l")
k = C("k")
d = D("d")

f.y = l
l.r = d
l.y = f
l.p = k
k.o = l
k.r = l
d.x = l
d.p = l
d.q = k
assert l.r.x.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
k = C("k")
d = D("d")

f.y = l
l.r = d
l.y = f
l.p = k
k.o = l
k.r = l
d.x = l
d.p = l
d.q = k
assert l.r.x.r.q.txt == "k"