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

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

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

k = A("k")
n = B("n")
d = C("d")
c = C("c")

k.o = d
k.u = d
n.u = k
n.o = k
d.u = k
d.x = k
d.y = c
c.u = k
c.x = k
c.y = d
assert c.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.u: C = None
        self.txt = txt

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

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

k = A("k")
n = B("n")
d = C("d")
c = C("c")

k.o = d
k.u = d
n.u = k
n.o = k
d.u = k
d.x = k
d.y = c
c.u = k
c.x = k
c.y = d
assert c.x.o.x.txt == "k"