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

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

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

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

l = A("l")
g = B("g")
i = C("i")
c = D("c")
b = A("b")
h = B("h")

l.p = c
l.q = i
l.o = i
g.q = l
g.p = i
i.p = b
i.r = b
i.t = c
c.v = b
c.y = l
c.p = l
c.o = h
b.p = c
b.q = i
b.o = i
h.q = b
h.p = i
assert l.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.q: C = None
        self.o: C = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
i = C("i")
c = D("c")
b = A("b")
h = B("h")

l.p = c
l.q = i
l.o = i
g.q = l
g.p = i
i.p = b
i.r = b
i.t = c
c.v = b
c.y = l
c.p = l
c.o = h
b.p = c
b.q = i
b.o = i
h.q = b
h.p = i
assert l.p.o.p.txt == "i"