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

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

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

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

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

i.p = c
g.o = j
g.u = b
j.x = i
h.x = j
b.x = j
c.p = i
assert i.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

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

i.p = c
g.o = j
g.u = b
j.x = i
h.x = j
b.x = j
c.p = i
assert i.p.p.p.txt == "c"