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

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

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

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

b = A("b")
m = B("m")
l = C("l")
d = D("d")

b.p = l
b.r = d
m.q = d
l.s = m
l.t = m
l.y = b
l.q = b
d.o = b
d.y = b
d.q = b
d.t = b
assert b.r.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: D = None
        self.txt = txt

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

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

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

b = A("b")
m = B("m")
l = C("l")
d = D("d")

b.p = l
b.r = d
m.q = d
l.s = m
l.t = m
l.y = b
l.q = b
d.o = b
d.y = b
d.q = b
d.t = b
assert b.r.y.r.txt == "d"