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

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

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

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

l = A("l")
c = B("c")
j = C("j")
a = D("a")

l.r = j
c.q = j
c.y = j
j.p = a
a.p = l
assert a.p.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

l = A("l")
c = B("c")
j = C("j")
a = D("a")

l.r = j
c.q = j
c.y = j
j.p = a
a.p = l
assert a.p.r.p.p.txt == "l"